Commit 4826d646 authored by marcoscano's avatar marcoscano Committed by Wim Leers

Issue #3018270 by marcoscano, Wim Leers: Fix CS violations in HEAD

parent 728e672d
# Developing
* Issues should be filed at http://drupal.org/project/issues/entity_embed
* Pull requests can be made against https://github.com/drupal-media/entity_embed/pulls
......@@ -72,7 +72,7 @@ function hook_entity_embed_context_alter(array &$context, \Drupal\Core\Entity\En
}
/**
* Alter the context of an particular embedded entity type before it is rendered.
* Alter the context of a particular embedded entity type before it is rendered.
*
* @param array &$context
* The context array.
......
......@@ -55,8 +55,7 @@ function entity_embed_update_8002() {
}
/**
* Updates allowed HTML for all filter format config entities that have an
* Entity Embed button.
* Updates allowed HTML for all filter configs that have an Entity Embed button.
*/
function entity_embed_update_8003() {
$buttons = \Drupal::entityTypeManager()->getStorage('embed_button')->loadMultiple();
......
......@@ -2,8 +2,7 @@
/**
* @file
* Framework for allowing entities to be embedded using CKEditor plugin and text
* format.
* Framework for allowing entities to be embedded in CKEditor.
*/
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -28,6 +27,7 @@ function entity_embed_help($route_name, RouteMatchInterface $route_match) {
return $output;
}
}
/**
* Implements hook_theme().
*/
......@@ -49,14 +49,16 @@ function entity_embed_theme() {
* - element: An associative array containing the properties of the element.
* Properties used: #attributes, #children.
*/
function template_preprocess_entity_embed_container(&$variables) {
function template_preprocess_entity_embed_container(array &$variables) {
$variables['element'] += ['#attributes' => []];
$variables['attributes'] = $variables['element']['#attributes'];
$variables['children'] = $variables['element']['#children'];
}
/**
* Implements hook_entity_embed_display_plugins_alter() on behalf of file.module.
* Implements hook_entity_embed_display_plugins_alter().
*
* Implementation on behalf of the file module.
*/
function file_entity_embed_display_plugins_alter(array &$plugins) {
// The RSS enclosure field formatter is not usable for Entity Embed.
......@@ -64,7 +66,9 @@ function file_entity_embed_display_plugins_alter(array &$plugins) {
}
/**
* Implements hook_entity_embed_display_plugins_alter() on behalf of taxonomy.module.
* Implements hook_entity_embed_display_plugins_alter().
*
* Implementation on behalf of the taxonomy module.
*/
function taxonomy_entity_embed_display_plugins_alter(array &$plugins) {
// The RSS category field formatter is not usable for Entity Embed.
......@@ -90,7 +94,7 @@ function entity_embed_entity_embed_display_plugins_for_context_alter(array &$def
/**
* Implements hook_form_FORM_ID_alter().
*/
function entity_embed_form_filter_format_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
function entity_embed_form_filter_format_edit_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// Add an additional validate callback so we can ensure the order of filters
// is correct.
$form['#validate'][] = 'entity_embed_filter_format_edit_form_validate';
......@@ -117,13 +121,13 @@ function entity_embed_filter_format_edit_form_validate($form, FormStateInterface
if (isset($filters['filter_align']['weight']) && $filters['filter_align']['weight'] <= $filters['entity_embed']['weight']) {
$form_state->setErrorByName('filters', t('The %entity-embed-filter-label filter needs to be placed before the %align-filter-label filter.', [
'%entity-embed-filter-label' => $get_filter_label('entity_embed'),
'%align-filter-label' => $get_filter_label('filter_align')
'%align-filter-label' => $get_filter_label('filter_align'),
]));
}
if (isset($filters['filter_caption']['weight']) && $filters['filter_caption']['weight'] <= $filters['entity_embed']['weight']) {
$form_state->setErrorByName('filters', t('The %entity-embed-filter-label filter needs to be placed before the %caption-filter-label filter.', [
'%entity-embed-filter-label' => $get_filter_label('entity_embed'),
'%caption-filter-label' => $get_filter_label('filter_caption')
'%caption-filter-label' => $get_filter_label('filter_caption'),
]));
}
}
......
......@@ -32,9 +32,9 @@ class EntityEmbedDisplay extends Plugin {
/**
* The human-readable name of the Entity Embed Display plugin.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label = '';
......
......@@ -34,6 +34,7 @@ class EntityEmbedBuilder implements EntityEmbedBuilderInterface {
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager $display_manager
* The entity embed display plugin manager.
*/
public function __construct(ModuleHandlerInterface $module_handler, EntityEmbedDisplayManager $display_manager) {
$this->moduleHandler = $module_handler;
......
......@@ -35,7 +35,7 @@ abstract class EntityEmbedDisplayBase extends PluginBase implements ContainerFac
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
......@@ -54,8 +54,14 @@ abstract class EntityEmbedDisplayBase extends PluginBase implements ContainerFac
public $attributes = [];
/**
* {@inheritdoc}
* Constructs an EntityEmbedDisplayBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
......@@ -94,8 +100,7 @@ abstract class EntityEmbedDisplayBase extends PluginBase implements ContainerFac
}
/**
* Validates that this Entity Embed Display plugin applies to the current
* entity type.
* Validates that this display plugin applies to the current entity type.
*
* This checks the plugin annotation's 'entity_types' value, which should be
* an array of entity types that this plugin can process, or FALSE if the
......@@ -266,7 +271,7 @@ abstract class EntityEmbedDisplayBase extends PluginBase implements ContainerFac
/**
* Gets the entity from the current context.
*
* @todo Where doe sthis come from? The value must come from somewhere, yet
* @todo Where does this come from? The value must come from somewhere, yet
* this does not implement any context-related interfaces. This is an *input*,
* so we need cache contexts and possibly cache tags to reflect where this
* came from. We need that for *everything* that this class does that relies
......@@ -274,6 +279,7 @@ abstract class EntityEmbedDisplayBase extends PluginBase implements ContainerFac
* global that breaks cacheability metadata.
*
* @return \Drupal\Core\Entity\EntityInterface
* The entity from the current context.
*/
public function getEntityFromContext() {
if ($this->hasContextValue('entity')) {
......@@ -321,6 +327,8 @@ abstract class EntityEmbedDisplayBase extends PluginBase implements ContainerFac
* Gets the current language code.
*
* @return string
* The langcode present in the 'data-langcode', if present, or the current
* langcode from the language manager, otherwise.
*/
public function getLangcode() {
$langcode = $this->getAttributeValue('data-langcode');
......
......@@ -113,7 +113,7 @@ class EntityEmbedDisplayManager extends DefaultPluginManager {
* Returns plugin definitions that should be displayed in the UI.
*/
protected function filterExposedDefinitions(array $definitions) {
return array_filter($definitions, function($definition) {
return array_filter($definitions, function ($definition) {
return empty($definition['no_ui']);
});
}
......
......@@ -15,7 +15,7 @@ use Drupal\node\Entity\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
* Base class for field formatter display plugins.
*/
abstract class FieldFormatterEntityEmbedDisplayBase extends EntityEmbedDisplayBase {
use PluginDependencyTrait;
......@@ -51,6 +51,12 @@ abstract class FieldFormatterEntityEmbedDisplayBase extends EntityEmbedDisplayBa
/**
* Constructs a FieldFormatterEntityEmbedDisplayBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager
......
......@@ -81,6 +81,8 @@ class EntityEmbedDialog extends FormBase {
/**
* The entity browser settings from the entity embed button.
*
* @var array
*/
protected $entityBrowserSettings = [];
......@@ -131,8 +133,12 @@ class EntityEmbedDialog extends FormBase {
}
/**
* {@inheritdoc}
* Form constructor.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param \Drupal\editor\EditorInterface $editor
* The editor to which this dialog corresponds.
* @param \Drupal\embed\EmbedButtonInterface $embed_button
......@@ -209,7 +215,8 @@ class EntityEmbedDialog extends FormBase {
* The form structure.
*/
public function buildSelectStep(array &$form, FormStateInterface $form_state) {
// Entity element is calculated on every AJAX request/submit. See ::buildForm().
// Entity element is calculated on every AJAX request/submit.
// See self::buildForm().
$entity_element = $form_state->get('entity_element');
/** @var \Drupal\embed\EmbedButtonInterface $embed_button */
$embed_button = $form_state->get('embed_button');
......@@ -355,7 +362,8 @@ class EntityEmbedDialog extends FormBase {
* The form structure.
*/
public function buildEmbedStep(array $form, FormStateInterface $form_state) {
// Entity element is calculated on every AJAX request/submit. See ::buildForm().
// Entity element is calculated on every AJAX request/submit.
// See self::buildForm().
$entity_element = $form_state->get('entity_element');
/** @var \Drupal\embed\EmbedButtonInterface $embed_button */
$embed_button = $form_state->get('embed_button');
......@@ -552,7 +560,11 @@ class EntityEmbedDialog extends FormBase {
// Also log an exception.
if (empty($display_plugin_options)) {
$form_state->setError($element, $this->t('No display options available for the selected entity. Please select another entity.'));
$this->logger('entity_embed')->warning('No display options available for "@type:" entity "@id" while embedding using button "@button". Please ensure that at least one Entity Embed Display plugin is allowed for this embed button which is available for this entity.', ['@type' => $entity_type, '@id' => $entity->id(), '@button' => $embed_button->id()]);
$this->logger('entity_embed')->warning('No display options available for "@type:" entity "@id" while embedding using button "@button". Please ensure that at least one Entity Embed Display plugin is allowed for this embed button which is available for this entity.', [
'@type' => $entity_type,
'@id' => $entity->id(),
'@button' => $embed_button->id(),
]);
}
}
}
......@@ -607,6 +619,8 @@ class EntityEmbedDialog extends FormBase {
* The form array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
* @param string $step
* The next step name, such as 'select', 'review' or 'embed'.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* The ajax response.
......@@ -718,8 +732,8 @@ class EntityEmbedDialog extends FormBase {
*
* @param array $form
* An associative array containing the structure of the form.
* @param FormStateInterface $form_state
* An associative array containing the current state of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*
* @return \Drupal\Core\Ajax\AjaxResponse
* The ajax response.
......@@ -756,11 +770,12 @@ class EntityEmbedDialog extends FormBase {
}
// Filter out empty attributes.
$values['attributes'] = array_filter($values['attributes'], function($value) {
$values['attributes'] = array_filter($values['attributes'], function ($value) {
return (bool) Unicode::strlen((string) $value);
});
// Allow other modules to alter the values before getting submitted to the WYSIWYG.
// Allow other modules to alter the values before getting submitted to the
// WYSIWYG.
$this->moduleHandler->alter('entity_embed_values', $values, $entity, $display, $form_state);
$response->addCommand(new EditorDialogSave($values));
......@@ -783,8 +798,7 @@ class EntityEmbedDialog extends FormBase {
}
/**
* Returns the allowed Entity Embed Display plugins given an embed button and
* an entity.
* Returns the allowed display plugins given an embed button and an entity.
*
* @param \Drupal\embed\EmbedButtonInterface $embed_button
* The embed button.
......@@ -806,8 +820,10 @@ class EntityEmbedDialog extends FormBase {
}
/**
* Registers JS callback that gets entities from entity browser and updates
* form values accordingly.
* Registers JS callbacks.
*
* Callbacks are responsible for getting entities from entity browser and
* updating form values accordingly.
*/
public function registerJSCallback(RegisterJSCallbacks $event) {
if ($event->getBrowserID() == $this->entityBrowser->id()) {
......@@ -819,6 +835,7 @@ class EntityEmbedDialog extends FormBase {
* Load the current entity browser and its settings from the form state.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
protected function loadEntityBrowser(FormStateInterface $form_state) {
$this->entityBrowser = NULL;
......
......@@ -18,7 +18,7 @@ class FieldFormatterDeriver extends DeriverBase implements ContainerDeriverInter
/**
* The manager for formatter plugins.
*
* @var \Drupal\Core\Field\FormatterPluginManager.
* @var \Drupal\Core\Field\FormatterPluginManager
*/
protected $formatterManager;
......
......@@ -158,7 +158,8 @@ class EntityEmbedFilter extends FilterBase implements ContainerFactoryPluginInte
$depth--;
}
else {
$entity_output = '<img src="' . file_create_url('core/modules/media/images/icons/no-thumbnail.png') . '" width="180" height="180" alt="' . $this->t('Deleted content encountered, site owner alerted.') . '" />';
$alt_text = $this->t('Deleted content encountered, site owner alerted.');
$entity_output = '<img src="' . file_create_url('core/modules/media/images/icons/no-thumbnail.png') . '" width="180" height="180" alt="' . $alt_text . '" />';
throw new EntityNotFoundException(sprintf('Unable to load embedded %s entity %s.', $entity_type, $id));
}
}
......
......@@ -36,8 +36,14 @@ class ImageFieldFormatter extends FileFieldFormatter {
protected $imageFactory;
/**
* {@inheritdoc}
* Constructs an ImageFieldFormatter object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager service.
* @param \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager
......
......@@ -30,6 +30,8 @@ class EntityEmbedTwigExtension extends \Twig_Extension {
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\entity_embed\EntityEmbedBuilderInterface $builder
* The Entity embed builder service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityEmbedBuilderInterface $builder) {
$this->entityTypeManager = $entity_type_manager;
......
......@@ -2,6 +2,7 @@
/**
* @file
* Update hook test file.
*/
use Drupal\Core\Database\Database;
......
......@@ -3,4 +3,3 @@ type: module
description: 'Support module for the Entity Embed module tests.'
core: 8.x
package: Testing
version: VERSION
......@@ -19,7 +19,10 @@ class EntityEmbedTestTwigController {
}
/**
* Menu callback for testing entity_embed twig extension using 'label' Entity Embed Display plugin.
* Menu callback.
*
* Used for testing entity_embed twig extension using 'label' Entity Embed
* Display plugin.
*/
public function labelPluginRender() {
return [
......@@ -31,7 +34,10 @@ class EntityEmbedTestTwigController {
}
/**
* Menu callback for testing entity_embed twig extension using 'label' Entity Embed Display plugin without linking to the node.
* Menu callback.
*
* Used for testing entity_embed twig extension using 'label' Entity Embed
* Display plugin without linking to the node.
*/
public function labelPluginNoLinkRender() {
return [
......
......@@ -55,11 +55,6 @@ class EntityEmbedDialogTest extends EntityEmbedTestBase {
// Ensure form structure of the 'select' step and submit form.
$this->assertFieldByName('entity_id', '', 'Entity ID/UUID field is present.');
// $edit = ['attributes[data-entity-id]' => $this->node->id()];
// $this->drupalPostAjaxForm(NULL, $edit, 'op');
// Ensure form structure of the 'embed' step and submit form.
// $this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');.
}
/**
......
......@@ -21,7 +21,12 @@ abstract class EntityEmbedTestBase extends BrowserTestBase {
*
* @var array
*/
protected static $modules = ['entity_embed', 'entity_embed_test', 'node', 'ckeditor'];
protected static $modules = [
'entity_embed',
'entity_embed_test',
'node',
'ckeditor',
];
/**
* The test user.
......@@ -95,6 +100,7 @@ abstract class EntityEmbedTestBase extends BrowserTestBase {
* Retrieves a sample file of the specified type.
*
* @return \Drupal\file\FileInterface
* The test file created.
*/
protected function getTestFile($type_name, $size = NULL) {
// Get a file to upload.
......
......@@ -41,7 +41,7 @@ class EntityEmbedUpdateHookTest extends UpdatePathTestBase {
protected function doSelectionTest() {
parent::doSelectionTest();
$this->assertRaw('8002 - Updates the default mode settings.');
$this->assertRaw('8003 - Updates allowed HTML for all filter format config entities that have an Entity Embed button.');
$this->assertRaw('8003 - Updates allowed HTML for all filter configs that have an Entity Embed button.');
}
/**
......
......@@ -2,8 +2,6 @@
namespace Drupal\Tests\entity_embed\FunctionalJavascript;
use Drupal\editor\Entity\Editor;
/**
* Tests the entity_embed dialog controller and route.
*
......@@ -68,12 +66,6 @@ class EntityEmbedDialogTest extends EntityEmbedTestBase {
foreach ($plugins as $plugin) {
$this->assertSession()->optionExists('Display as', $plugin);
}
/*$this->drupalPostForm(NULL, $edit, 'Next');
// Ensure form structure of the 'embed' step and submit form.
$this->assertFieldByName('attributes[data-entity-embed-display]', 'Entity Embed Display plugin field is present.');
// Check that 'Embed' is a primary button.
$this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Embed', 'Embed is a primary button');*/
}
/**
......
......@@ -21,7 +21,12 @@ abstract class EntityEmbedTestBase extends WebDriverTestBase {
*
* @var array
*/
protected static $modules = ['entity_embed', 'entity_embed_test', 'node', 'ckeditor'];
protected static $modules = [
'entity_embed',
'entity_embed_test',
'node',
'ckeditor',
];
/**
* The test user.
......@@ -84,10 +89,13 @@ abstract class EntityEmbedTestBase extends WebDriverTestBase {
$this->drupalLogin($this->webUser);
// Create a sample node to be embedded.
$settings = array();
$settings = [];
$settings['type'] = 'page';
$settings['title'] = 'Embed Test Node';
$settings['body'] = array('value' => 'This node is to be used for embedding in other nodes.', 'format' => 'custom_format');
$settings['body'] = [
'value' => 'This node is to be used for embedding in other nodes.',
'format' => 'custom_format',
];
$this->node = $this->drupalCreateNode($settings);
}
......@@ -95,6 +103,7 @@ abstract class EntityEmbedTestBase extends WebDriverTestBase {
* Retrieves a sample file of the specified type.
*
* @return \Drupal\file\FileInterface
* The created file entity.
*/
protected function getTestFile($type_name, $size = NULL) {
// Get a file to upload.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment