Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds_content / dds_content.install
Size: Mime:
<?php

use Drupal\editor\Entity\Editor;

function dds_content_install() {
  $metatag_global = \Drupal\metatag\Entity\MetatagDefaults::load('global');
  $tags = $metatag_global->get('tags');
  $tags['og_site_name'] = '[site:name]';
  $metatag_global->set('tags', $tags);
  $metatag_global->save();

  $default_tags = [
    'image_src' => '[dds_content:dds_content_primary_image]',
    'description' => '[node:field_teaser]',
    'og_image' => '[dds_content:dds_content_primary_image]',
    'og_description' => '[node:field_teaser]',
    'og_title' => '[node:title] | [site:name]',
  ];

  $metatag_front = \Drupal\metatag\Entity\MetatagDefaults::load('front');
  $tags = $metatag_front->get('tags');
  $tags = array_merge($tags, $default_tags);
  $metatag_front->set('tags', $tags);
  $metatag_front->save();

  $metatag_403 = \Drupal\metatag\Entity\MetatagDefaults::load('403');
  $tags = $metatag_403->get('tags');
  $tags = array_merge($tags, $default_tags);
  $metatag_403->set('tags', $tags);
  $metatag_403->save();

  $metatag_404 = \Drupal\metatag\Entity\MetatagDefaults::load('404');
  $tags = $metatag_404->get('tags');
  $tags = array_merge($tags, $default_tags);
  $metatag_404->set('tags', $tags);
  $metatag_404->save();

  $metatag_node = \Drupal\metatag\Entity\MetatagDefaults::load('node');
  $tags = $metatag_node->get('tags');
  $tags = array_merge($tags, $default_tags);
  $metatag_node->set('tags', $tags);
  $metatag_node->save();

  if (\Drupal::moduleHandler()->moduleExists('autosave_form')) {
    $config_factory = \Drupal::configFactory();
    $settings = $config_factory->getEditable('autosave_form.settings');
    $data = $settings->getRawData();
    $data['interval'] = 10000;
    $data['active_on']['content_entity_forms'] = true;
    $data['active_on']['config_entity_forms'] = false;
    $data['allowed_content_entity_types']['node'] = ['bundles' => []];
    $settings->setData($data);
    $settings->save();
  }

}

function _install_linkit_config() {
  /** @var \Drupal\editor\Entity\Editor[] $rte_formats */
  $rte_formats = Editor::loadMultiple();

  foreach ($rte_formats as $id => $editor) {
    $editor_config = \Drupal::configFactory()->getEditable('editor.editor.'.$id);

    // If the config wasn't loaded, we skip it.
    if ($editor_config === NULL) {
      continue;
    }

    $editor_dependencies = $editor_config->get('dependencies');
    $editor_settings = $editor_config->get('settings');

    // If linkit hasn't beed added as a module dependency, we add it.
    if (
      empty($editor_dependencies['module']) ||
      (
        !empty($editor_dependencies['module']) &&
        !in_array('linkit', $editor_dependencies['module'], FALSE)
      )
    ) {
      $editor_dependencies['module'][] = 'linkit';
    }
    $editor_config->set('dependencies', $editor_dependencies);

    // Configure the settings so that it uses linkit.
    // First, add the plugin config
    $editor_settings['plugins']['linkit'] = [
      'linkit_profile' => 'content',
    ];
    // Second, replace the normal link button with a linkit button.
    $editor_rows = $editor_settings['toolbar']['rows'];
    // We need to do this for any potential row in the editor.
    foreach ($editor_rows as $index => $rows) {
      // Only process non-empty rows.
      if (empty($rows)) {
        continue;
      }
      // Loop through each row to replace drupal links with linkit.
      foreach ($rows as $row_index => $row) {
        // Only process non-empty rows.
        if (empty($row['items'])) {
          continue;
        }
        // And each item in said row.
        foreach ($row['items'] as $item_index => $item) {
          // If it isn't a drupal link, we just skip it.
          if ($item !== 'DrupalLink') {
            continue;
          }
          // Replace it with Linkit.
          $editor_settings['toolbar']['rows'][$index][$row_index]['items'][$item_index] = 'Linkit';
        }
      }
    }
    $editor_config->set('settings', $editor_settings);

    $editor_config->save();
  }
}