function lightning_media_views_pre_view in Lightning Media 8.4
Implements hook_views_pre_view().
File
- ./
lightning_media.module, line 470 - Core media asset support for Lightning.
Code
function lightning_media_views_pre_view(ViewExecutable $view, $display_id) {
// If the field_media_in_library field doesn't exist, there is no point in
// continuing here.
$field_map = Drupal::service('entity_field.manager')
->getFieldMap();
if (empty($field_map['media']['field_media_in_library'])) {
return;
}
if ($view
->id() === 'media_library' && strpos($display_id, 'widget') === 0) {
$filters = $view->display_handler
->getOption('filters');
// Filter out media items where field_media_in_library is FALSE. If the view
// already has stored configuration for this field, it will be respected.
$filters += [
'field_media_in_library_value' => [
'id' => 'field_media_in_library_value',
'table' => 'media__field_media_in_library',
'field' => 'field_media_in_library_value',
'relationship' => 'none',
'group_type' => 'group',
'admin_label' => '',
'operator' => '=',
'value' => '1',
'group' => 1,
'exposed' => FALSE,
'expose' => [
'operator_id' => '',
'label' => '',
'description' => '',
'use_operator' => FALSE,
'operator' => '',
'operator_limit_selection' => FALSE,
'operator_list' => [],
'identifier' => '',
'required' => FALSE,
'remember' => FALSE,
'multiple' => FALSE,
'remember_roles' => [
'authenticated' => 'authenticated',
],
],
'is_grouped' => FALSE,
'group_info' => [
'label' => '',
'description' => '',
'identifier' => '',
'optional' => TRUE,
'widget' => 'select',
'multiple' => FALSE,
'remember' => FALSE,
'default_group' => 'All',
'default_group_multiple' => [],
'group_items' => [],
],
'plugin_id' => 'boolean',
],
];
$view->display_handler
->setOption('filters', $filters);
}
}