.../Core/Entity/Entity/EntityFormDisplay.php | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php index e18b0b6..932c074 100644 --- a/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php @@ -7,8 +7,7 @@ namespace Drupal\Core\Entity\Entity; -use Drupal\Core\Cache\Cache; -use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Entity\EntityDisplayPluginCollection; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; @@ -36,6 +35,13 @@ class EntityFormDisplay extends EntityDisplayBase implements EntityFormDisplayIn protected $displayContext = 'form'; /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * Returns the entity_form_display object used to build an entity form. * * Depending on the configuration of the form mode for the entity bundle, this @@ -117,6 +123,7 @@ public static function collectRenderDisplay(FieldableEntityInterface $entity, $f */ public function __construct(array $values, $entity_type) { $this->pluginManager = \Drupal::service('plugin.manager.field.widget'); + $this->renderer = \Drupal::service('renderer'); parent::__construct($values, $entity_type); } @@ -152,9 +159,6 @@ public function getRenderer($field_name) { * {@inheritdoc} */ public function buildForm(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state) { - /** @var \Drupal\Core\Render\RendererInterface $renderer */ - $renderer = \Drupal::service('renderer'); - // Set #parents to 'top-level' by default. $form += array('#parents' => array()); @@ -174,18 +178,18 @@ public function buildForm(FieldableEntityInterface $entity, array &$form, FormSt // Associate the cache tags for the field definition & field storage // definition. $field_definition = $this->getFieldDefinition($name); - if ($field_definition instanceof ConfigEntityInterface) { - $renderer->addDependency($form['name'], $field_definition); + if ($field_definition instanceof CacheableDependencyInterface) { + $this->renderer->addDependency($form[$name], $field_definition); $field_storage_definition = $field_definition->getFieldStorageDefinition(); - if ($field_storage_definition instanceof ConfigEntityInterface) { - $renderer->addDependency($form['name'], $field_storage_definition); + if ($field_storage_definition instanceof CacheableDependencyInterface) { + $this->renderer->addDependency($form[$name], $field_storage_definition); } } } } // Associate the cache tags for the form display. - $renderer->addDependency($form, $this); + $this->renderer->addDependency($form, $this); // Add a process callback so we can assign weights and hide extra fields. $form['#process'][] = array($this, 'processForm');