diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFieldFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFieldFormatter.php index 0e43086..92bf745 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFieldFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFieldFormatter.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; use Drupal\Core\Entity\EntityDisplayBase; -use Drupal\Core\Entity\EntityFieldManager; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -60,14 +60,18 @@ class EntityReferenceFieldFormatter extends EntityReferenceFormatterBase impleme /** * The list of supported fields, prepared as options (machine_name => label). * - * @var array + * @var string[] */ protected $availableFieldOptions; /** * The list of available formatters, keyed by field type. * - * @var array + * Each element of this array is an associative array, where keys are + * formatter machine names, and the values are formatter human-readable + * labels. + * + * @var array[] */ protected $availableFormatterOptions; @@ -94,7 +98,7 @@ public static function create(ContainerInterface $container, array $configuratio * Constructs a EntityReferenceReferencedEntityFieldFormatter object. * * @param string $plugin_id - * The plugin_id for the formatter. + * The formatter's plugin ID. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition @@ -107,7 +111,7 @@ public static function create(ContainerInterface $container, array $configuratio * The view mode. * @param array $third_party_settings * Any third party settings. - * @param \Drupal\Core\Entity\EntityFieldManager $entity_field_manager + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager * The entity field manager. * @param \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager * The formatter plugin manager. @@ -116,7 +120,7 @@ public static function create(ContainerInterface $container, array $configuratio * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info * The entity type bundle info. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityFieldManager $entity_field_manager, FormatterPluginManager $formatter_plugin_manager, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) { + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityFieldManagerInterface $entity_field_manager, FormatterPluginManager $formatter_plugin_manager, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); $this->entityFieldManager = $entity_field_manager; $this->formatterPluginManager = $formatter_plugin_manager; @@ -193,7 +197,6 @@ protected function getAvailableFieldOptions() { foreach ($target_bundles as $bundle) { // Fetch all fields present on each target bundle. $bundle_field_names = []; - /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */ foreach ($this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle) as $field_machine_name => $field_definition) { // We use ::isDisplayConfigurable() to filter out the base fields that // should not be exposed to the user. The only exception to this is the @@ -243,14 +246,14 @@ protected function getAvailableFormatterOptions(FieldStorageDefinitionInterface /** * Ajax callback for field name change. */ - public static function onFieldNameChange(array $form, FormStateInterface $form_state) { + public static function onFieldNameChange(array &$form, FormStateInterface $form_state) { return $form['fields'][$form_state->get('plugin_settings_edit')]['plugin']['settings_edit_form']['settings']; } /** * Ajax callback for formatter type change. */ - public static function onFormatterTypeChange(array $form, FormStateInterface $form_state) { + public static function onFormatterTypeChange(array &$form, FormStateInterface $form_state) { return $form['fields'][$form_state->get('plugin_settings_edit')]['plugin']['settings_edit_form']['settings']['settings']; } @@ -330,7 +333,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) { $settings_form = $formatter->settingsForm([], $form_state); } else { - drupal_set_message('Could not instantiate the formatter plugin, please choose a different formatter.', 'error'); + drupal_set_message($this->t('Could not instantiate the formatter plugin, please choose a different formatter.'), 'error'); } $form['settings'] = $settings_form; $form['settings']['#prefix'] = '