diff --git a/core/modules/comment/config/install/system.action.comment_delete_action.yml b/core/modules/comment/config/install/system.action.comment_delete_action.yml index 5034172..89dd7c9 100644 --- a/core/modules/comment/config/install/system.action.comment_delete_action.yml +++ b/core/modules/comment/config/install/system.action.comment_delete_action.yml @@ -4,4 +4,6 @@ status: true langcode: en type: comment plugin: comment_delete_action -configuration: { } +dependencies: + module: + - comment diff --git a/core/modules/comment/config/optional/views.view.comment.yml b/core/modules/comment/config/optional/views.view.comment.yml index 603e4fa..2a704a8 100644 --- a/core/modules/comment/config/optional/views.view.comment.yml +++ b/core/modules/comment/config/optional/views.view.comment.yml @@ -198,7 +198,7 @@ display: relationship: none group_type: group admin_label: '' - label: Title + label: Subject exclude: false alter: alter_text: false @@ -320,6 +320,57 @@ display: entity_type: comment entity_field: name plugin_id: field + commented_entity_label: + id: commented_entity_label + table: comment + field: commented_entity_label + relationship: none + group_type: group + admin_label: '' + label: 'Posted in' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + link_to_entity: true + entity_type: comment + plugin_id: commented_entity_label changed: id: changed table: comment_field_data @@ -368,7 +419,7 @@ display: hide_empty: false empty_zero: false hide_alter_empty: true - date_format: fallback + date_format: short custom_date_format: '' timezone: '' entity_type: comment diff --git a/core/modules/comment/config/schema/comment.views.schema.yml b/core/modules/comment/config/schema/comment.views.schema.yml index a3256d3..9b59207 100644 --- a/core/modules/comment/config/schema/comment.views.schema.yml +++ b/core/modules/comment/config/schema/comment.views.schema.yml @@ -20,6 +20,14 @@ views.field.comment_bulk_form: type: views_field_bulk_form label: 'Comment bulk form' +views.field.commented_entity_label: + type: views_field + label: 'Commented entity label' + mapping: + link_to_entity: + type: boolean + label: 'Link to entity' + views.field.comment_last_timestamp: type: views.field.date label: 'Last comment date' diff --git a/core/modules/comment/src/CommentViewsData.php b/core/modules/comment/src/CommentViewsData.php index fa6c5df..49bbbd4 100644 --- a/core/modules/comment/src/CommentViewsData.php +++ b/core/modules/comment/src/CommentViewsData.php @@ -118,6 +118,14 @@ public function getViewsData() { ), ); + $data['comment']['commented_entity_label'] = array( + 'title' => t('Label of commented entity'), + 'help' => t('Provide a label of commented entity.'), + 'field' => array( + 'id' => 'commented_entity_label', + ), + ); + $data['comment']['comment_bulk_form'] = array( 'title' => t('Comment operations bulk form'), 'help' => t('Add a form element that lets you run operations on multiple comments.'), diff --git a/core/modules/comment/src/Plugin/views/field/CommentedEntityLabel.php b/core/modules/comment/src/Plugin/views/field/CommentedEntityLabel.php new file mode 100644 index 0000000..13764b5 --- /dev/null +++ b/core/modules/comment/src/Plugin/views/field/CommentedEntityLabel.php @@ -0,0 +1,135 @@ +entityManager = $manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity.manager') + ); + } + + /** + * {@inheritdoc} + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['link_to_entity'] = array('default' => FALSE); + return $options; + } + + /** + * {@inheritdoc} + */ + public function buildOptionsForm(&$form, FormStateInterface $form_state) { + $form['link_to_entity'] = array( + '#title' => $this->t('Link to entity'), + '#description' => $this->t('Make entity label a link to entity page.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_entity']), + ); + parent::buildOptionsForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function query() { + } + + /** + * {@inheritdoc} + */ + public function render(ResultRow $values) { + /** @var \Drupal\comment\CommentInterface $comment */ + if(($comment = $values->_entity) && isset($this->loadedCommentedEntities[$comment->getCommentedEntityTypeId()]) && isset($this->loadedCommentedEntities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()])) { + + /** @var $entity \Drupal\Core\Entity\EntityInterface */ + $entity = $this->loadedCommentedEntities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()]; + + if (!empty($this->options['link_to_entity'])) { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['url'] = $entity->urlInfo(); + } + + return $this->sanitizeValue($entity->label()); + } + return ''; + } + + /** + * {@inheritdoc} + */ + public function preRender(&$values) { + parent::preRender($values); + + $entity_ids_per_type = array(); + /** @var \Drupal\views\ResultRow $value */ + foreach ($values as $value) { + /** @var \Drupal\comment\CommentInterface $entity */ + if ($entity = $value->_entity) { + $entity_ids_per_type[$entity->getCommentedEntityTypeId()][] = $entity->getCommentedEntityId(); + } + } + + foreach ($entity_ids_per_type as $type => $ids) { + $this->loadedCommentedEntities[$type] = $this->entityManager->getStorage($type)->loadMultiple($ids); + } + } + +}