summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-01-11 12:49:14 (GMT)
committerNathaniel Catchpole2016-01-11 12:49:14 (GMT)
commit6cbd448feaee5ad6e0ded280689da59d3159a53f (patch)
treeec45eb53af3b0778388e9d9298549ea0b2cd13ee
parentb746956f0b41f24470b1eca5d02aab32d8b38bba (diff)
Issue #2562099 by Dave Reid, amateescu: EntityReferenceEntityFormatter uses entity_view() and does not inject the entity manager
-rw-r--r--core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php35
1 files changed, 30 insertions, 5 deletions
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
index c2f23cf..78b62b3 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
@@ -7,6 +7,8 @@
namespace Drupal\Core\Field\Plugin\Field\FieldFormatter;
+use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
@@ -36,6 +38,20 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
protected $loggerFactory;
/**
+ * The entity type manager.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+ */
+ protected $entityTypeManager;
+
+ /**
+ * The entity type manager.
+ *
+ * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
+ */
+ protected $entityDisplayRepository;
+
+ /**
* Constructs a StringFormatter instance.
*
* @param string $plugin_id
@@ -54,10 +70,16 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
* Any third party settings settings.
* @param LoggerChannelFactoryInterface $logger_factory
* The logger factory.
+ * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+ * The entity type manager.
+ * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
+ * The entity display repository.
*/
- public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory) {
+ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->loggerFactory = $logger_factory;
+ $this->entityTypeManager = $entity_type_manager;
+ $this->entityDisplayRepository = $entity_display_repository;
}
/**
@@ -72,7 +94,9 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
$configuration['label'],
$configuration['view_mode'],
$configuration['third_party_settings'],
- $container->get('logger.factory')
+ $container->get('logger.factory'),
+ $container->get('entity_type.manager'),
+ $container->get('entity_display.repository')
);
}
@@ -92,7 +116,7 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements['view_mode'] = array(
'#type' => 'select',
- '#options' => \Drupal::entityManager()->getViewModeOptions($this->getFieldSetting('target_type')),
+ '#options' => $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type')),
'#title' => t('View mode'),
'#default_value' => $this->getSetting('view_mode'),
'#required' => TRUE,
@@ -107,7 +131,7 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
public function settingsSummary() {
$summary = array();
- $view_modes = \Drupal::entityManager()->getViewModeOptions($this->getFieldSetting('target_type'));
+ $view_modes = $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type'));
$view_mode = $this->getSetting('view_mode');
$summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]) ? $view_modes[$view_mode] : $view_mode));
@@ -131,7 +155,8 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase implem
}
if ($entity->id()) {
- $elements[$delta] = entity_view($entity, $view_mode, $entity->language()->getId());
+ $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId());
+ $elements[$delta] = $view_builder->view($entity, $view_mode, $entity->language()->getId());
// Add a resource attribute to set the mapping property's value to the
// entity's url. Since we don't know what the markup of the entity will