X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FField%2FPlugin%2FField%2FFieldFormatter%2FStringFormatter.php;h=320005ceef003029eb1fc2b1539f1511b9432404;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=95ab0b2cf48e0230e903a156787ef390dd0cebcc;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php b/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php index 95ab0b2cf..320005cee 100644 --- a/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php +++ b/web/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php @@ -2,7 +2,8 @@ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FormatterBase; @@ -28,6 +29,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInterface { + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + /** * Constructs a StringFormatter instance. * @@ -45,13 +53,13 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt * The view mode. * @param array $third_party_settings * Any third party settings settings. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityManagerInterface $entity_manager) { + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); - $this->entityManager = $entity_manager; + $this->entityTypeManager = $entity_type_manager; } /** @@ -66,7 +74,7 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], - $container->get('entity.manager') + $container->get('entity_type.manager') ); } @@ -86,7 +94,7 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt public function settingsForm(array $form, FormStateInterface $form_state) { $form = parent::settingsForm($form, $form_state); - $entity_type = $this->entityManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId()); + $entity_type = $this->entityTypeManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId()); $form['link_to_entity'] = [ '#type' => 'checkbox', @@ -103,7 +111,7 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt public function settingsSummary() { $summary = []; if ($this->getSetting('link_to_entity')) { - $entity_type = $this->entityManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId()); + $entity_type = $this->entityTypeManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId()); $summary[] = $this->t('Linked to the @entity_label', ['@entity_label' => $entity_type->getLabel()]); } return $summary; @@ -116,8 +124,8 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt $elements = []; $url = NULL; if ($this->getSetting('link_to_entity')) { - // For the default revision this falls back to 'canonical' - $url = $items->getEntity()->urlInfo('revision'); + // For the default revision this falls back to 'canonical'. + $url = $this->getEntityUrl($items->getEntity()); } foreach ($items as $delta => $item) { @@ -155,4 +163,18 @@ class StringFormatter extends FormatterBase implements ContainerFactoryPluginInt ]; } + /** + * Gets the URI elements of the entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity object. + * + * @return \Drupal\Core\Url + * The URI elements of the entity. + */ + protected function getEntityUrl(EntityInterface $entity) { + // For the default revision this falls back to 'canonical'. + return $entity->toUrl('revision'); + } + }