sector_blog-8.x-1.0-beta1/sector_blog.module
sector_blog.module
<?php
use Drupal\views\Views;
use Drupal\views\ViewExecutable;
use Drupal\views\Entity\View;
use Drupal\taxonomy\Entity\Term;
/**
*
* Implements hook_modules_installed().
*
* We don't attach terms to our content created by Sector add ons so they fit
* into the system nicely. Unfortunately we need one of these terms as a
* filter, and they aren't available during hook_install.
* @param $modules
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function sector_blog_modules_installed($modules) {
// We only want to run this on install of this module.
if (in_array('sector_blog', $modules)) {
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => 'Feature', 'vid' => 'blog_post_category']);
$term = array_pop($terms);
$tid = $term->id();
// Load the blog view.
$view = View::load('sector_blog');
// Load the display we want to alter and add the new TID to the filter.
$display = &$view->getDisplay('block_2')['display_options'];
$display['filters']['field_blog_post_category_target_id']['value'][$tid] = $tid;
$view->save();
}
}
