You are here

config_selector_ui_test.install in Configuration selector 8.2

The Configuration Selector UI Test module install methods.

File

tests/modules/config_selector_ui_test/config_selector_ui_test.install
View source
<?php

/**
 * @file
 * The Configuration Selector UI Test module install methods.
 */
use Drupal\Core\Config\FileStorage;

/**
 * Implements hook_install().
 */
function config_selector_ui_test_install() {

  // Save ourselves from having to manage a view.
  $node_optional_dir = drupal_get_path('module', 'node') . '/config/optional';
  $node_config_storage = new FileStorage($node_optional_dir);
  $view_data = $node_config_storage
    ->read('views.view.content');
  _config_selector_ui_test_create_new_view('feature_test_1', 'feature_test', 'A good view', 1, FALSE, $view_data);
  _config_selector_ui_test_create_new_view('feature_test_2', 'feature_test', 'An even better view', 2, FALSE, $view_data);
  _config_selector_ui_test_create_new_view('feature_test_3', 'feature_test', 'The best view', 3, TRUE, $view_data);
}

/**
 * Creates a new view based on the supplied params.
 *
 * @param string $new_id
 *   The new view ID.
 * @param string $feature
 *   The Configuration Selector feature to add it to.
 * @param string $description
 *   The description text.
 * @param int $priority
 *   The priority.
 * @param bool $status
 *   The status.
 * @param array $view_data
 *   The complete data for the view.
 *
 * @return \Drupal\views\ViewEntityInterface
 *   The new view entity.
 */
function _config_selector_ui_test_create_new_view($new_id, $feature, $description, $priority, $status, array $view_data) {
  $view_storage = \Drupal::entityTypeManager()
    ->getStorage('view');
  $view_data['id'] = $new_id;

  // Make life simple for testing and ensure the views are removed on uninstall.
  $view_data['dependencies']['enforced']['module'] = [
    'config_selector_ui_test',
  ];

  /** @var \Drupal\views\ViewEntityInterface $view */
  $view = $view_storage
    ->createFromStorageRecord($view_data);
  $view
    ->setStatus($status);
  $view
    ->setThirdPartySetting('config_selector', 'feature', $feature);
  $view
    ->setThirdPartySetting('config_selector', 'priority', $priority);
  $view
    ->set('label', $new_id);
  $view
    ->set('description', $description);
  $view
    ->save();
  return $view;
}

Functions

Namesort descending Description
config_selector_ui_test_install Implements hook_install().
_config_selector_ui_test_create_new_view Creates a new view based on the supplied params.