You are here

function content_lock_views_data in Content locking (anti-concurrent editing) 8.2

Same name and namespace in other branches
  1. 8 content_lock.module \content_lock_views_data()
  2. 6.2 views/content_lock.views.inc \content_lock_views_data()
  3. 6 views/content_lock.views.inc \content_lock_views_data()
  4. 7.3 views/content_lock.views.inc \content_lock_views_data()
  5. 7 views/content_lock.views.inc \content_lock_views_data()
  6. 7.2 views/content_lock.views.inc \content_lock_views_data()

Implements hook_views_data().

File

./content_lock.module, line 219
Content lock - Main functions of the module.

Code

function content_lock_views_data() {

  // Define the return array.
  $data = [];
  $data['content_lock']['table']['group'] = t('Content lock');
  $data['content_lock']['table']['provider'] = 'content_lock';
  $data['content_lock']['table']['join'] = [
    'users_field_data' => [
      'left_field' => 'uid',
      'field' => 'uid',
    ],
  ];
  $types = \Drupal::configFactory()
    ->get('content_lock.settings')
    ->get("types");
  $content_lock = \Drupal::service('content_lock');
  foreach (array_filter($types) as $type => $value) {
    $definition = \Drupal::entityTypeManager()
      ->getDefinition($type);
    $data['content_lock']['table']['join'][$definition
      ->getDataTable()] = [
      'left_field' => $definition
        ->getKey('id'),
      'field' => 'entity_id',
      'extra' => [
        [
          'field' => 'entity_type',
          'value' => $type,
        ],
      ],
    ];
    if ($content_lock
      ->isTranslationLockEnabled($type)) {
      $data['content_lock']['table']['join'][$definition
        ->getDataTable()]['extra'][] = [
        'left_field' => $definition
          ->getKey('langcode'),
        'field' => 'langcode',
      ];
    }
    $data['content_lock'][$definition
      ->getKey('id')] = [
      'title' => t('@type locked', [
        '@type' => $definition
          ->getLabel(),
      ]),
      'help' => t('The @type being locked.', [
        '@type' => $definition
          ->getLabel(),
      ]),
      'relationship' => [
        'base' => $definition
          ->getDataTable(),
        'base field' => $definition
          ->getKey('id'),
        'id' => 'standard',
        'label' => t('@type locked', [
          '@type' => $definition
            ->getLabel(),
        ]),
      ],
    ];
  }
  $data['content_lock']['uid'] = [
    'title' => t('Lock owner'),
    'help' => t('The user locking the node.'),
    'relationship' => [
      'base' => 'users_field_data',
      'base field' => 'uid',
      'id' => 'standard',
      'label' => t('Lock owner'),
    ],
  ];
  $data['content_lock']['timestamp'] = [
    'title' => t('Lock Date/Time'),
    'help' => t('Timestamp of the lock'),
    'field' => [
      'id' => 'date',
      'click sortable' => TRUE,
    ],
    'sort' => [
      'id' => 'date',
    ],
    'filter' => [
      'id' => 'date',
    ],
  ];
  $data['content_lock']['langcode'] = [
    'title' => t('Lock Language'),
    'help' => t('Language of the lock'),
    'field' => [
      'id' => 'language',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'language',
    ],
    'argument' => [
      'id' => 'language',
    ],
    'entity field' => 'langcode',
  ];
  $data['content_lock']['form_op'] = [
    'title' => t('Lock Form Operation'),
    'help' => t('Form operation of the lock'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
    'argument' => [
      'id' => 'string',
    ],
  ];
  $data['content_lock']['is_locked'] = [
    'real field' => 'timestamp',
    'title' => t('Is Locked'),
    'help' => t('Whether the node is currently locked'),
    'field' => [
      'id' => 'boolean',
      'click sortable' => TRUE,
    ],
    'sort' => [
      'id' => 'content_lock_sort',
    ],
    'filter' => [
      'id' => 'content_lock_filter',
    ],
  ];

  // Break link.
  $data['content_lock']['break'] = [
    'title' => t('Break link'),
    'help' => t('Link to break the content lock.'),
    'field' => [
      'id' => 'content_lock_break_link',
      'real field' => 'entity_id',
    ],
  ];
  return $data;
}