media_directories.install in Media Directories 8
Same filename and directory in other branches
Installation and update impementations.
File
media_directories.installView source
<?php
/**
* @file
* Installation and update impementations.
*/
use Drupal\views\Entity\View;
/**
* Implements hook_install().
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function media_directories_install() {
$filter = [
'id' => 'directory',
'table' => 'media_field_data',
'field' => 'directory',
'relationship' => 'none',
'group_type' => 'group',
'admin_label' => '',
'operator' => 'or',
'value' => [],
'group' => 1,
'exposed' => TRUE,
'expose' => [
'operator_id' => 'directory_op',
'label' => 'Directory',
'description' => '',
'use_operator' => FALSE,
'operator' => 'directory_op',
'identifier' => 'directory',
'required' => FALSE,
'remember' => FALSE,
'multiple' => FALSE,
'remember_roles' => [],
'reduce' => FALSE,
],
'is_grouped' => FALSE,
'group_info' => [],
'reduce_duplicates' => FALSE,
'error_message' => TRUE,
'entity_type' => 'media',
'entity_field' => 'directory',
'plugin_id' => 'media_directory',
];
// Alter Media library view configuration.
$view = View::load('media_library');
if ($view !== NULL) {
$default_display =& $view
->getDisplay('default');
$widget_display =& $view
->getDisplay('widget');
$widget_table_display =& $view
->getDisplay('widget_table');
$default_display['display_options']['filters'] = array_merge([
'directory' => $filter,
], $default_display['display_options']['filters']);
$widget_display['display_options']['filters'] = array_merge([
'directory' => $filter,
], $widget_display['display_options']['filters']);
$widget_table_display['display_options']['filters'] = array_merge([
'directory' => $filter,
], $widget_table_display['display_options']['filters']);
$view
->save();
unset($default_display);
}
// Alter default Media view configuration.
$view_table = View::load('media');
if ($view_table !== NULL) {
$default_display =& $view_table
->getDisplay('default');
$default_display['display_options']['filters'] = array_merge([
'directory' => $filter,
], $default_display['display_options']['filters']);
$view_table
->save();
}
}
/**
* Implements hook_uninstall().
*/
function media_directories_uninstall() {
// Remove Media library view configuration.
$view = View::load('media_library');
if ($view !== NULL) {
$default_display =& $view
->getDisplay('default');
$widget_display =& $view
->getDisplay('widget');
$widget_table_display =& $view
->getDisplay('widget_table');
if (isset($default_display['display_options']['filters']['directory'])) {
unset($default_display['display_options']['filters']['directory']);
}
if (isset($widget_display['display_options']['filters']['directory'])) {
unset($widget_display['display_options']['filters']['directory']);
}
if (isset($widget_table_display['display_options']['filters']['directory'])) {
unset($widget_table_display['display_options']['filters']['directory']);
}
$view
->save();
unset($default_display);
}
// Remove default Media view configuration.
$view_table = View::load('media');
if ($view_table !== NULL) {
$default_display =& $view_table
->getDisplay('default');
if (isset($default_display['display_options']['filters']['directory'])) {
unset($default_display['display_options']['filters']['directory']);
}
$view_table
->save();
}
}
Functions
Name | Description |
---|---|
media_directories_install | Implements hook_install(). |
media_directories_uninstall | Implements hook_uninstall(). |