diff --git a/ds.api.php b/ds.api.php index 5e8b7b9..5e2998d 100644 --- a/ds.api.php +++ b/ds.api.php @@ -78,7 +78,7 @@ function hook_ds_layout_settings_alter(array $record, \Drupal\Core\Form\FormStat * - entity * - entity_type * - bundle - * - view_mode + * - view_mode. * @param array $vars * All variables available for render. You can use this to add css classes. */ diff --git a/ds.module b/ds.module index d01634d..9942123 100644 --- a/ds.module +++ b/ds.module @@ -235,7 +235,7 @@ function ds_theme_registry_alter(&$theme_registry) { } /** - * Implements hook_form_alter(). + * Implements hook_form_FORM_ID_alter(). */ function ds_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) { $form_state->loadInclude('ds', 'inc', 'includes/field_ui'); diff --git a/includes/field_ui.inc b/includes/field_ui.inc index d20cb10..a055a46 100644 --- a/includes/field_ui.inc +++ b/includes/field_ui.inc @@ -230,7 +230,7 @@ function ds_field_ui_regions(array $form, FormStateInterface $form_state) { } // Add region. - // Core added regions to Field UI, which default to 'content' + // Core added regions to Field UI, which default to 'content'. if (!isset($row['region'])) { $split = 7; $default = (isset($field_regions[$name]) && isset($region_options[$field_regions[$name]])) ? $field_regions[$name] : 'hidden'; @@ -282,7 +282,7 @@ function ds_field_ui_layouts_validate($form, FormStateInterface $form_state) { // Only validate the layout settings if the layout hasn't changed. if (!$new_layout && !empty($layout)) { - /* @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout_plugin */ + /* @var \Drupal\Core\Layout\LayoutInterface $layout_plugin */ $layout_plugin = \Drupal::service('plugin.manager.core.layout')->createInstance($form_state->getValue('layout'), []); $layout_form = isset($form['layout_configuration']) ? $form['layout_configuration'] : []; foreach (Element::children($form) as $name) { diff --git a/modules/ds_devel/ds_devel.module b/modules/ds_devel/ds_devel.module index ced6d03..5e06144 100644 --- a/modules/ds_devel/ds_devel.module +++ b/modules/ds_devel/ds_devel.module @@ -10,7 +10,7 @@ */ function ds_devel_entity_type_alter(array &$entity_types) { /* @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - foreach ($entity_types as $entity_type_id => $entity_type) { + foreach ($entity_types as $entity_type) { if ($entity_type->hasViewBuilderClass() && $entity_type->hasLinkTemplate('canonical')) { $entity_type->setLinkTemplate('devel-markup', $entity_type->getLinkTemplate('canonical') . '/devel/markup'); } diff --git a/modules/ds_extras/ds_extras.module b/modules/ds_extras/ds_extras.module index 2d3b7d4..16775bf 100644 --- a/modules/ds_extras/ds_extras.module +++ b/modules/ds_extras/ds_extras.module @@ -19,7 +19,7 @@ use Drupal\Core\Url; function ds_extras_layout_alter(&$definitions) { if (\Drupal::config('ds_extras.settings')->get('hidden_region')) { /** @var \Drupal\Core\Layout\LayoutDefinition $layout */ - foreach ($definitions as $key => $layout) { + foreach ($definitions as $layout) { $regions = $layout->getRegions(); $regions['ds_hidden'] = ['label' => t('Hidden')]; $layout->setRegions($regions); diff --git a/src/Form/ChangeLayoutForm.php b/src/Form/ChangeLayoutForm.php index f63afb4..5e18fc7 100644 --- a/src/Form/ChangeLayoutForm.php +++ b/src/Form/ChangeLayoutForm.php @@ -29,16 +29,26 @@ class ChangeLayoutForm extends FormBase { protected $entityFieldManager; /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * ChangeLayoutForm constructor. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity type manager. * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager * The entity field manager. + * @param \Drupal\ds\Form\ModuleHandlerInterface $module_handler + * The module handler. */ - public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityFieldManagerInterface $entityFieldManager) { + public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityFieldManagerInterface $entityFieldManager, ModuleHandlerInterface $module_handler) { $this->entityTypeManager = $entityTypeManager; $this->entityFieldManager = $entityFieldManager; + $this->moduleHandler = $module_handler; } /** @@ -114,7 +124,7 @@ class ChangeLayoutForm extends FormBase { $region_info = [ 'region_options' => $regions, ]; - \Drupal::moduleHandler()->alter('ds_layout_region', $context, $region_info); + $this->moduleHandler->alter('ds_layout_region', $context, $region_info); $regions = $region_info['region_options']; $save_regions = []; @@ -133,7 +143,7 @@ class ChangeLayoutForm extends FormBase { $region_info = [ 'region_options' => $new_regions, ]; - \Drupal::moduleHandler()->alter('ds_layout_region', $context, $region_info); + $this->moduleHandler->alter('ds_layout_region', $context, $region_info); $new_layout->setRegions($region_info['region_options']); // Display the region options. @@ -148,7 +158,7 @@ class ChangeLayoutForm extends FormBase { ]; $form['region_' . $region]['ds_' . $region] = [ '#type' => 'select', - '#options' => $layout_options = $selectable_regions, + '#options' => $selectable_regions, '#default_value' => $region, ]; } @@ -215,7 +225,8 @@ class ChangeLayoutForm extends FormBase { unset($third_party_settings['regions']); // Map old regions to new ones. - foreach ($old_layout_info->getRegions() as $region => $region_title) { + $regions = array_keys($old_layout_info->getRegions()); + foreach ($regions as $region) { $new_region = $form_state->getValue('ds_' . $region); if ($new_region != '' && isset($old_layout['regions'][$region])) { foreach ($old_layout['regions'][$region] as $field) { @@ -228,20 +239,20 @@ class ChangeLayoutForm extends FormBase { } // Save configuration. - /* @var $entity_display \Drupal\Core\Entity\Display\EntityDisplayInterface*/ - $entity_display = $this->entityTypeManager + /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */ + $display = $this->entityTypeManager ->getStorage('entity_view_display') ->load($entity_type . '.' . $bundle . '.' . $display_mode); foreach (array_keys($third_party_settings) as $key) { - $entity_display->setThirdPartySetting('ds', $key, $third_party_settings[$key]); + $display->setThirdPartySetting('ds', $key, $third_party_settings[$key]); } - $entity_display->save(); + $display->save(); // Clear entity info cache. $this->entityFieldManager->clearCachedFieldDefinitions(); // Show message. - drupal_set_message(t('The layout change has been saved.')); + drupal_set_message($this->t('The layout change has been saved.')); } } diff --git a/src/Form/ClassesForm.php b/src/Form/ClassesForm.php index 0971f41..886fdb2 100644 --- a/src/Form/ClassesForm.php +++ b/src/Form/ClassesForm.php @@ -27,7 +27,7 @@ class ClassesForm extends ConfigFormBase { '#type' => 'textarea', '#title' => $this->t('CSS classes for regions'), '#default_value' => implode("\n", $config->get('classes.region')), - '#description' => t('Configure CSS classes which you can add to regions on the "manage display" screens. Add multiple CSS classes line by line.
If you want to have a friendly name, separate class and friendly name by |, but this is not required. eg:
class_name_1
class_name_2|Friendly name
class_name_3
'), + '#description' => $this->t('Configure CSS classes which you can add to regions on the "manage display" screens. Add multiple CSS classes line by line.
If you want to have a friendly name, separate class and friendly name by |, but this is not required. eg:
class_name_1
class_name_2|Friendly name
class_name_3
'), ]; // Only show field classes if DS extras module is enabled. diff --git a/src/Form/EmergencyForm.php b/src/Form/EmergencyForm.php index 076fcc5..7e43ff9 100644 --- a/src/Form/EmergencyForm.php +++ b/src/Form/EmergencyForm.php @@ -129,7 +129,7 @@ class EmergencyForm extends ConfigFormBase { */ public function submitFieldAttach(array &$form, FormStateInterface $form_state) { $this->state->set('ds.disabled', ($this->state->get('ds.disabled', FALSE) ? FALSE : TRUE)); - drupal_set_message(t('The configuration options have been saved.')); + drupal_set_message($this->t('The configuration options have been saved.')); } /** @@ -140,18 +140,19 @@ class EmergencyForm extends ConfigFormBase { $save = FALSE; $region_blocks = $this->config('ds_extras.settings')->get('region_blocks'); $remove = $form_state->getValue('remove_block_region'); + if ($this->moduleHandler->moduleExists('block')) { + $block_storage = \Drupal::entityTypeManager()->getStorage('block'); + } foreach ($remove as $key => $value) { if ($value !== 0 && $key == $value) { $save = TRUE; // Make sure there is no active block instance for this ds block // region. - if (\Drupal::moduleHandler()->moduleExists('block')) { + if (isset($block_storage)) { $ids = \Drupal::entityQuery('block') ->condition('plugin', 'ds_region_block:' . $key) ->execute(); - /* @var \Drupal\block\BlockInterface $block_storage */ - $block_storage = \Drupal::service('entity_type.manager')->getStorage('block'); foreach ($block_storage->loadMultiple($ids) as $block) { $block->delete(); } @@ -162,7 +163,7 @@ class EmergencyForm extends ConfigFormBase { } if ($save) { - drupal_set_message(t('Block regions were removed.')); + drupal_set_message($this->t('Block regions were removed.')); // Clear cached block and ds plugin definitions. \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); diff --git a/src/Form/FieldFormBase.php b/src/Form/FieldFormBase.php index 812ff1b..8444dd4 100644 --- a/src/Form/FieldFormBase.php +++ b/src/Form/FieldFormBase.php @@ -245,7 +245,7 @@ class FieldFormBase extends ConfigFormBase implements ContainerInjectionInterfac // Redirect. $url = new Url('ds.fields_list'); $form_state->setRedirectUrl($url); - drupal_set_message(t('The field %field has been saved.', ['%field' => $field['label']])); + drupal_set_message($this->t('The field %field has been saved.', ['%field' => $field['label']])); } } diff --git a/src/Plugin/DsField/BlockBase.php b/src/Plugin/DsField/BlockBase.php index 21490d8..03125f2 100644 --- a/src/Plugin/DsField/BlockBase.php +++ b/src/Plugin/DsField/BlockBase.php @@ -115,6 +115,9 @@ abstract class BlockBase extends DsFieldBase implements ContainerFactoryPluginIn /** * Returns the plugin ID of the block. + * + * @return string + * The plugin ID. */ protected function blockPluginId() { return ''; @@ -122,6 +125,9 @@ abstract class BlockBase extends DsFieldBase implements ContainerFactoryPluginIn /** * Returns the config of the block. + * + * @return array + * Block plugin configuration. */ protected function blockConfig() { return []; @@ -129,15 +135,14 @@ abstract class BlockBase extends DsFieldBase implements ContainerFactoryPluginIn /** * Return the block entity. + * + * @return \Drupal\Core\Block\BlockPluginInterface + * The block plugin instance. */ protected function getBlock() { if (!$this->block) { // Create an instance of the block. - /* @var $block BlockPluginInterface */ - $block_id = $this->blockPluginId(); - $block = $this->blockManager->createInstance($block_id); - - $this->block = $block; + $this->block = $this->blockManager->createInstance($this->blockPluginId()); } return $this->block; diff --git a/src/Plugin/DsField/BundleField.php b/src/Plugin/DsField/BundleField.php index 460cc62..4018ee7 100644 --- a/src/Plugin/DsField/BundleField.php +++ b/src/Plugin/DsField/BundleField.php @@ -2,9 +2,6 @@ namespace Drupal\ds\Plugin\DsField; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - /** * Defines a generic bundle field. * @@ -16,44 +13,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class BundleField extends DsFieldBase { /** - * The EntityDisplayRepository service. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Constructs a Display Suite field plugin. - */ - public function __construct($configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity.manager') - ); - } - - /** * {@inheritdoc} */ public function build() { - $config = $this->getConfiguration(); - $entity = $this->entity(); - $bundles_info = $this->entityTypeManager->getBundleInfo($config['field']['entity_type']); - $output = $bundles_info[$entity->bundle()]['label']; - return [ - '#markup' => $output, + '#markup' => $this->entity()->getEntityType()->getBundleLabel(), ]; } diff --git a/src/Plugin/DsField/Date.php b/src/Plugin/DsField/Date.php index b843eb5..e062cce 100644 --- a/src/Plugin/DsField/Date.php +++ b/src/Plugin/DsField/Date.php @@ -65,12 +65,12 @@ abstract class Date extends DsFieldBase { * {@inheritdoc} */ public function formatters() { + /** @var \Drupal\Core\Datetime\DateFormatInterface[] $date_types */ $date_types = $this->entityTypeManager->getStorage('date_format') ->loadMultiple(); $date_formatters = []; foreach ($date_types as $machine_name => $value) { - /* @var $value \Drupal\Core\Datetime\DateFormatterInterface */ if ($value->isLocked()) { continue; } diff --git a/src/Plugin/DsField/DsFieldBase.php b/src/Plugin/DsField/DsFieldBase.php index ddc7f8f..a87d056 100644 --- a/src/Plugin/DsField/DsFieldBase.php +++ b/src/Plugin/DsField/DsFieldBase.php @@ -2,6 +2,7 @@ namespace Drupal\ds\Plugin\DsField; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -119,13 +120,10 @@ abstract class DsFieldBase extends PluginBase implements DsFieldInterface { if (isset($this->configuration['entity_type'])) { return $this->configuration['entity_type']; } - elseif ($entity = $this->entity()) { - /* @var $entity EntityInterface */ + elseif (($entity = $this->entity()) && $entity instanceof EntityInterface) { return $entity->getEntityTypeId(); } - else { - return ''; - } + return ''; } /** diff --git a/src/Plugin/DsField/DsFieldInterface.php b/src/Plugin/DsField/DsFieldInterface.php index ae0371f..eacc500 100644 --- a/src/Plugin/DsField/DsFieldInterface.php +++ b/src/Plugin/DsField/DsFieldInterface.php @@ -13,13 +13,16 @@ interface DsFieldInterface extends ConfigurablePluginInterface, ContainerFactory /** * Renders a field. + * + * @return array + * A renderable array representing the content of the field. */ public function build(); /** * Returns the summary of the chosen settings. * - * @param $settings + * @param array $settings * Contains the settings of the field. * * @return array @@ -29,6 +32,14 @@ interface DsFieldInterface extends ConfigurablePluginInterface, ContainerFactory /** * The form that holds the settings for this plugin. + * + * @param array $form + * The form definition array for the field configuration form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * + * @return array + * The renderable form array representing the entire configuration form. */ public function settingsForm($form, FormStateInterface $form_state); @@ -42,6 +53,9 @@ interface DsFieldInterface extends ConfigurablePluginInterface, ContainerFactory /** * Returns if the field is allowed on the field UI screen. + * + * @return bool + * TRUE when field allowed, FALSE otherwise. */ public function isAllowed(); @@ -55,36 +69,57 @@ interface DsFieldInterface extends ConfigurablePluginInterface, ContainerFactory /** * Gets the current entity type. + * + * @return string + * The entity type ID. */ public function getEntityTypeId(); /** * Gets the current bundle. + * + * @return string + * The configured bundle of the entity. */ public function bundle(); /** * Gets the view mode. + * + * @return string + * The configured view mode. */ public function viewMode(); /** * Gets the field configuration. + * + * @return array + * The configured field settings. */ public function getFieldConfiguration(); /** * Gets the field name. + * + * @return string + * The field name. */ public function getName(); /** * Returns the title of the field. + * + * @return string + * The configured field title. */ public function getTitle(); /** * Defines if we are dealing with a multivalue field. + * + * @return bool + * TRUE when field has multiple values, FALSE otherwise. */ public function isMultiple(); diff --git a/src/Plugin/DsField/DynamicBlockField.php b/src/Plugin/DsField/DynamicBlockField.php index 3bd139c..72ee2b8 100644 --- a/src/Plugin/DsField/DynamicBlockField.php +++ b/src/Plugin/DsField/DynamicBlockField.php @@ -38,13 +38,15 @@ class DynamicBlockField extends BlockBase { /** * Returns the title of the block. + * + * @return array|string + * Renderable array of views block tile or string title. */ public function getTitle() { $field = $this->getFieldConfiguration(); $title = $field['title']; if (isset($field['properties']['use_block_title']) && $field['properties']['use_block_title'] == TRUE) { - /* @var $block BlockPluginInterface */ $block = $this->getBlock(); if ($block instanceof ViewsBlock) { diff --git a/src/Plugin/DsField/Entity.php b/src/Plugin/DsField/Entity.php index 0ad37a6..a2c0a2f 100644 --- a/src/Plugin/DsField/Entity.php +++ b/src/Plugin/DsField/Entity.php @@ -77,7 +77,9 @@ abstract class Entity extends DsFieldBase { // Print the chosen view mode or the default one. $config = $this->getConfiguration(); $entity_view_mode = $config['entity_view_mode']; - $summary[] = 'View mode: ' . $view_modes[$entity_view_mode]['label']; + $summary[] = $this->t('View mode: @label', [ + '@label' => $view_modes[$entity_view_mode]['label'], + ]); return $summary; } diff --git a/src/Plugin/DsField/User/User.php b/src/Plugin/DsField/User/User.php index f3add7f..ef0395e 100644 --- a/src/Plugin/DsField/User/User.php +++ b/src/Plugin/DsField/User/User.php @@ -52,18 +52,12 @@ class User extends Entity { * {@inheritdoc} */ public function build() { - $view_mode = $this->getEntityViewMode(); - - /* @var $node \Drupal\node\NodeInterface */ + /** @var \Drupal\node\NodeInterface $node */ $node = $this->entity(); - $uid = $node->getOwnerId(); - $user = $this->entityTypeManager - ->getStorage('user') - ->load($uid); $build = $this->entityTypeManager ->getViewBuilder('user') - ->view($user, $view_mode); + ->view($node->getOwner(), $this->getEntityViewMode()); return $build; } diff --git a/src/Plugin/DsFieldTemplate/DsFieldTemplateBase.php b/src/Plugin/DsFieldTemplate/DsFieldTemplateBase.php index 84e4c0a..075ca90 100644 --- a/src/Plugin/DsFieldTemplate/DsFieldTemplateBase.php +++ b/src/Plugin/DsFieldTemplate/DsFieldTemplateBase.php @@ -107,12 +107,11 @@ abstract class DsFieldTemplateBase extends PluginBase implements DsFieldTemplate * {@inheritdoc} */ public function defaultConfiguration() { - $config = []; - $config['lb'] = ''; - $config['lb-col'] = \Drupal::config('ds.settings')->get('ft-show-colon'); - $config['classes'] = []; - - return $config; + return [ + 'lb' => '', + 'lb-col' => \Drupal::config('ds.settings')->get('ft-show-colon'), + 'classes' => [], + ]; } /** diff --git a/src/Plugin/DsFieldTemplate/DsFieldTemplateInterface.php b/src/Plugin/DsFieldTemplate/DsFieldTemplateInterface.php index eb9191a..7adaf3e 100644 --- a/src/Plugin/DsFieldTemplate/DsFieldTemplateInterface.php +++ b/src/Plugin/DsFieldTemplate/DsFieldTemplateInterface.php @@ -5,47 +5,73 @@ namespace Drupal\ds\Plugin\DsFieldTemplate; use Drupal\Core\Entity\EntityInterface; /** - * Base class for all the ds plugins. + * Defines a common interface for all ds field template plugins. */ interface DsFieldTemplateInterface { /** * Lets you add you add additional form element for your layout. + * + * @param array $form + * Nested array of form elements that comprise the form. */ public function alterForm(&$form); /** * Gets the entity this layout belongs too. + * + * @return \Drupal\Core\Entity\EntityInterface + * The entity. */ public function getEntity(); /** * Sets the entity this layout belong too. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity. */ public function setEntity(EntityInterface $entity); /** * Massages the values before they get rendered. + * + * @param array $field_settings + * The ds field settings. + * @param array $values + * The values. */ public function massageRenderValues(&$field_settings, $values); /** * Gets the chosen theme function. + * + * @return string + * The theme function. */ public function getThemeFunction(); /** * Creates default configuration for the layout. + * + * @return array + * Keyed array of default settings. */ public function defaultConfiguration(); /** * Get the selected configuration. + * + * @return array + * Keyed array of configuration values. */ public function getConfiguration(); /** * Set the configuration for this layout. + * + * @param array $configuration + * Keyed array of new configuration values. */ public function setConfiguration(array $configuration); diff --git a/src/Plugin/DsFieldTemplate/Reset.php b/src/Plugin/DsFieldTemplate/Reset.php index 7899ed4..d74f596 100644 --- a/src/Plugin/DsFieldTemplate/Reset.php +++ b/src/Plugin/DsFieldTemplate/Reset.php @@ -31,10 +31,9 @@ class Reset extends DsFieldTemplateBase { * {@inheritdoc} */ public function defaultConfiguration() { - $config = []; - $config['lb'] = ''; - - return $config; + return [ + 'lb' => '', + ]; } /** diff --git a/src/Plugin/DsLayout.php b/src/Plugin/DsLayout.php index ef9da0f..aa0bb9a 100644 --- a/src/Plugin/DsLayout.php +++ b/src/Plugin/DsLayout.php @@ -76,7 +76,7 @@ class DsLayout extends LayoutDefault implements PluginFormInterface { $form['region_wrapper']['attributes'] = [ '#type' => 'textfield', '#title' => $this->t('Layout attributes'), - '#description' => 'E.g. role|navigation,data-something|some value', + '#description' => $this->t('E.g. role|navigation,data-something|some value'), '#default_value' => $configuration['attributes'], '#weight' => 11, ]; @@ -200,7 +200,7 @@ class DsLayout extends LayoutDefault implements PluginFormInterface { $this->configuration['classes'] = $form_state->getValue('ds_classes', $defaults['classes']); // Do not save empty classes. - foreach ($this->configuration['classes'] as $region_name => &$classes) { + foreach ($this->configuration['classes'] as &$classes) { foreach ($classes as $class) { if (empty($class)) { unset($classes[$class]); diff --git a/src/Plugin/views/Entity/Render/DefaultLanguageRenderer.php b/src/Plugin/views/Entity/Render/DefaultLanguageRenderer.php index e2999f4..af17f5d 100644 --- a/src/Plugin/views/Entity/Render/DefaultLanguageRenderer.php +++ b/src/Plugin/views/Entity/Render/DefaultLanguageRenderer.php @@ -10,17 +10,9 @@ use Drupal\views\ResultRow; class DefaultLanguageRenderer extends RendererBase { /** - * Returns the language code associated to the given row. - * - * @param \Drupal\views\ResultRow $row - * The result row. - * @param $relationship - * The relationship. - * - * @return string - * A language code. + * {@inheritdoc} */ - public function getLangcode(ResultRow $row, $relationship = NULL) { + public function getLangcode(ResultRow $row) { return $row->_entity->getUntranslated()->language()->getId(); }