Commit 457b4fa7 authored by George's avatar George
Browse files

Issue #3199988 - Add entity operations field.

parent fdc2c73e
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ function config_view_views_data() {
          $table = &$data[$id];
          $table['table']['group'] = $name;
          $table['table']['provider'] = $id;
          $table['table']['entity type'] = $id;
          $fields = ConfigViewHelper::getMapping($id);

          if (empty($fields['id'])) {
@@ -65,11 +66,19 @@ function config_view_views_data() {
            'query_id' => 'config_view_query',
          ];

          $table['operation'] = [
            'title' => t('Operations'),
            'help' => t('Operations'),
            'field' => [
              'id' => 'config_entity_operations',
            ],
            'argument' => ['type' => $id],
          ];

          // Dynamically adding suitable handlers for all indexed fields.
          foreach ($fields as $key => $value) {
            if (isset($value['label']) && isset($value['type'])) {
              $properties = ConfigViewHelper::getFieldParameters($value);

              if (!empty($properties)) {
                $table[$key] = [
                  'title' => $value['label'],
+30 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\config_view\Plugin\views\field;

use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;

/**
 * Field handler to display entity label optionally linked to entity page.
 *
 * @ViewsField("config_entity_operations")
 */
class ConfigEntityOperations extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    // Doesn't work as there is no alias.
    // $value = $this->getValue($values, 'type');.
    $entity_type = $this->getEntityType();
    $entity = $values->_relationship_objects[NULL][0];
    $list_builder = \Drupal::entityTypeManager()->getListBuilder($entity_type);
    return [
      '#type' => 'operations',
      '#links' => $list_builder->getOperations($entity),
    ];
  }

}