diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 1792762..4597761 100644 --- a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -16,7 +16,6 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\field\Entity\FieldConfig; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -67,11 +66,11 @@ public static function defaultSettings() { protected $viewBuilder; /** - * The comment render controller. + * The entity form builder. * * @var \Drupal\Core\Entity\EntityFormBuilderInterface */ - protected $formBuilder; + protected $entityFormBuilder; /** * {@inheritdoc} @@ -115,15 +114,15 @@ public static function create(ContainerInterface $container, array $configuratio * The comment storage. * @param \Drupal\Core\Entity\EntityViewBuilderInterface $comment_view_builder * The comment view builder. - * @param \Drupal\Core\Entity\EntityFormBuilderInterface $form_builder + * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder * The entity form builder. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, CommentStorageInterface $comment_storage, EntityViewBuilderInterface $comment_view_builder, EntityFormBuilderInterface $form_builder) { + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, CommentStorageInterface $comment_storage, EntityViewBuilderInterface $comment_view_builder, EntityFormBuilderInterface $entity_form_builder) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); $this->viewBuilder = $comment_view_builder; $this->storage = $comment_storage; $this->currentUser = $current_user; - $this->formBuilder = $form_builder; + $this->entityFormBuilder = $entity_form_builder; } /** @@ -187,16 +186,13 @@ public function viewElements(FieldItemListInterface $items) { // All users in the "anonymous" role can use the same form: it is fine // for this form to be stored in the render cache. if ($this->currentUser->isAnonymous()) { - $entity_type = $entity->getEntityTypeId(); - $field = Fieldconfig::loadByName($entity_type, $field_name); - $values = array( - 'entity_type' => $entity_type, + $comment = $this->storage->create(array( + 'entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id(), 'field_name' => $field_name, - 'comment_type' => $field->getSetting('bundle'), + 'comment_type' => $this->getFieldSetting('comment_type'), 'pid' => NULL, - ); - $comment = $this->storage->create($values); + )); $output['comment_form'] = $this->entityFormBuilder->getForm($comment); } // All other users need a user-specific form, which would break the