You are here

boxout.install in Boxout 8

Install/Update hooks for Boxout.

File

boxout.install
View source
<?php

/**
 * @file
 * Install/Update hooks for Boxout.
 */
use Drupal\editor\Entity\Editor;

/**
 * Helper to configure Boxout on editors.
 */
function _boxout_update_editors() {
  foreach ([
    'basic_html',
    'full_html',
  ] as $id) {
    if ($editor = Editor::load($id)) {
      switch ($id) {
        case 'basic_html':

          // Add boxout to allowed html.
          $config = \Drupal::configFactory()
            ->getEditable('filter.format.basic_html');
          $key = 'filters.filter_html.settings.allowed_html';
          $config_value = $config
            ->get($key);
          $config_value .= '<div class="boxout default plain">';
          $config
            ->set($key, $config_value)
            ->save(TRUE);
          break;
      }
      $config = $editor
        ->getSettings();

      // Add boxout to toolbar.
      foreach ($config['toolbar']['rows'][0] as &$row) {

        // Try to add Boxout on toolbar.
        if ($row['name'] == 'Tools') {
          if (!array_search('Boxout', $row['items'])) {
            $row['items'][] = 'Boxout';
          }
        }
      }

      // Save settings.
      $editor
        ->setSettings($config);
      $editor
        ->save();
      \Drupal::service('plugin.manager.editor')
        ->clearCachedDefinitions();
    }
  }
}

/**
 * Implements hook_install().
 */
function boxout_install() {
  _boxout_update_editors();
}

/**
 * Update filter.
 */
function boxout_update_8001() {
  _boxout_update_editors();
}

Functions

Namesort descending Description
boxout_install Implements hook_install().
boxout_update_8001 Update filter.
_boxout_update_editors Helper to configure Boxout on editors.