You are here

hashtags.install in Hashtags 8

File

hashtags.install
View source
<?php

use Drupal\filter\Entity\FilterFormat;
use Drupal\field\Entity\FieldConfig;

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

  // add Hashtags filter to the system Text formats (FilterFormat)
  FilterFormat::load('full_html')
    ->setFilterConfig('filter_hashtags', [
    'status' => TRUE,
    'weight' => 10,
  ])
    ->save();
  FilterFormat::load('basic_html')
    ->setFilterConfig('filter_hashtags', [
    'status' => TRUE,
    'weight' => 10,
  ])
    ->save();

  // clear filter caches
  filter_formats_reset();
}

/**
 * Implements hook_uninstall().
 */
function hashtags_uninstall() {
  $hashtags_field_name = \Drupal::config('hashtags.settings')
    ->get('hashtags_taxonomy_terms_field_name');
  $entity_types = _hashtags_get_content_entity_types();
  foreach ($entity_types as $entity_type) {
    $bundles = \Drupal::service('entity.manager')
      ->getBundleInfo($entity_type);
    foreach ($bundles as $bundle => $bundle_info) {
      if (_hashtags_is_field_exists($entity_type, $bundle, $hashtags_field_name)) {
        $hashtags_field = FieldConfig::loadByName($entity_type, $bundle, $hashtags_field_name);
        if (!empty($hashtags_field)) {
          $hashtags_field
            ->delete();
        }
        $activated_text_fields = _hashtags_get_activated_text_fields($entity_type, $bundle);
        foreach ($activated_text_fields as $field_name) {
          $text_field = \Drupal::entityTypeManager()
            ->getStorage('field_config')
            ->load("{$entity_type}.{$bundle}.{$field_name}");
          if (!empty($text_field)) {
            $text_field
              ->unsetThirdPartySetting('hashtags', 'hashtags_activate');
            $text_field
              ->save();
          }
        }
      }
    }
  }
}

Functions

Namesort descending Description
hashtags_install Implements hook_install().
hashtags_uninstall Implements hook_uninstall().