You are here

function thunder_update_8005 in Thunder 8.2

Add author filter to content view.

File

./thunder.install, line 220
Install, update and uninstall functions for the thunder installation profile.

Code

function thunder_update_8005() {

  /** @var \Drupal\views\Entity\View $view */
  $view = View::load('content');
  if (empty($view
    ->getDisplay('default')['display_options']['filters']['uid'])) {
    $uid['uid'] = [
      'id' => 'uid',
      'table' => 'node_field_data',
      'field' => 'uid',
      'relationship' => 'none',
      'group_type' => 'group',
      'admin_label' => '',
      'operator' => 'in',
      'value' => [],
      'group' => 1,
      'exposed' => TRUE,
      'expose' => [
        'operator_id' => 'uid_op',
        'label' => 'Authored by',
        'description' => '',
        'use_operator' => FALSE,
        'operator' => 'uid_op',
        'identifier' => 'uid',
        'required' => FALSE,
        'remember' => FALSE,
        'multiple' => FALSE,
        'remember_roles' => [
          'authenticated' => 'authenticated',
          'anonymous' => '0',
          'editor' => '0',
          'seo' => '0',
          'administrator' => '0',
        ],
        'reduce' => FALSE,
      ],
      'is_grouped' => FALSE,
      'group_info' => [
        'label' => '',
        'description' => '',
        'identifier' => '',
        'optional' => TRUE,
        'widget' => 'select',
        'multiple' => FALSE,
        'remember' => FALSE,
        'default_group' => 'All',
        'default_group_multiple' => [],
        'group_items' => [],
      ],
      'entity_type' => 'node',
      'entity_field' => 'uid',
      'plugin_id' => 'user_name',
    ];
    $newArray = array_slice($view
      ->getDisplay('default')['display_options']['filters'], 0, 4, TRUE) + $uid + array_slice($view
      ->getDisplay('default')['display_options']['filters'], 4, NULL, TRUE);
    $view
      ->getDisplay('default')['display_options']['filters'] = $newArray;
    $view
      ->save();
  }
}