Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Adds an embed_button image style. #8

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/install/image.style.embed_button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: embed_button
label: 'Embed Button (32x32)'
effects:
0cea8388-fe1f-4202-af26-385bad55e186:
id: image_scale_and_crop
data:
width: 32
height: 32
weight: 0
uuid: 0cea8388-fe1f-4202-af26-385bad55e186
langcode: en
dependencies:
module:
- image
2 changes: 2 additions & 0 deletions embed.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ name: Embed
type: module
description: 'Provide a framework for various different types of embeds in WYSIWYG editors, common functionality, interfaces, and standards.'
core: 8.x
dependencies:
- image
3 changes: 2 additions & 1 deletion src/Entity/EmbedButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public function getIconFile() {
*/
public function getIconUrl() {
if ($image = $this->getIconFile()) {
return $image->url();
$style = \Drupal\image\Entity\ImageStyle::load('embed_button');
return $style->buildUri($image->getFileUri());
}
else {
return file_create_url(drupal_get_path('module', 'embed') . '/js/plugins/drupalembed/embed.png');
Expand Down
28 changes: 24 additions & 4 deletions src/Form/EmbedButtonForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Drupal\ckeditor\CKEditorPluginManager;
use Drupal\embed\EmbedDisplay\EmbedDisplayManager;
use Drupal\embed\EmbedType\EmbedTypeManager;
Expand Down Expand Up @@ -59,6 +60,13 @@ class EmbedButtonForm extends EntityForm {
*/
protected $entityEmbedConfig;

/**
* The element info manager.
*
* @var \Drupal\Core\Render\ElementInfoManagerInterface
*/
protected $elementInfo;

/**
* Constructs a new EmbedButtonForm.
*
Expand All @@ -73,12 +81,13 @@ class EmbedButtonForm extends EntityForm {
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(EntityManagerInterface $entity_manager, EmbedTypeManager $embed_type_manager, EmbedDisplayManager $display_plugin_manager, CKEditorPluginManager $ckeditor_plugin_manager, ConfigFactoryInterface $config_factory) {
public function __construct(EntityManagerInterface $entity_manager, EmbedTypeManager $embed_type_manager, EmbedDisplayManager $display_plugin_manager, CKEditorPluginManager $ckeditor_plugin_manager, ConfigFactoryInterface $config_factory, ElementInfoManagerInterface $element_info) {
$this->entityManager = $entity_manager;
$this->typePluginManager = $embed_type_manager;
$this->displayPluginManager = $display_plugin_manager;
$this->ckeditorPluginManager = $ckeditor_plugin_manager;
$this->entityEmbedConfig = $config_factory->get('embed.settings');
$this->elementInfo = $element_info;
}

/**
Expand All @@ -90,7 +99,8 @@ public static function create(ContainerInterface $container) {
$container->get('plugin.manager.embed.type'),
$container->get('plugin.manager.embed.display'),
$container->get('plugin.manager.ckeditor.plugin'),
$container->get('config.factory')
$container->get('config.factory'),
$container->get('element_info')
);
}

Expand Down Expand Up @@ -155,12 +165,22 @@ public function form(array $form, FormStateInterface $form_state) {
$form['icon_file'] = array(
'#title' => $this->t('Button icon image'),
'#type' => 'managed_file',
'#description' => $this->t("Image for the button to be shown in CKEditor toolbar. Leave empty to use the default Entity icon."),
'#description' => $this->t("Image for the button to be shown in CKEditor toolbar. Leave empty to use the default Entity icon. For best results upload a 32x32 or 16x16 image."),
'#upload_location' => $upload_location,
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
'file_validate_image_resolution' => array('32x32', '16x16'),
),
'#multiple' => FALSE,
// Styling for nice image upload.
'#process' => array_merge($this->elementInfo->getInfo('managed_file')['#process'], array(array('\Drupal\image\Plugin\Field\FieldWidget\ImageWidget', 'process'))),
'#preview_image_style' => 'embed_button',
'#title_field' => 0,
'#title_field_required' => 0,
'#alt_field' => 0,
'#alt_field_required' => 0,
'#display_field' => 0,
'#description_field' => 0,
'#cardinality' => 1,
);
if ($file = $embed_button->getIconFile()) {
$form['icon_file']['#default_value'] = array('target_id' => $file->id());
Expand Down