You are here

yoast_seo.install in Real-time SEO for Drupal 8.2

Same filename and directory in other branches
  1. 8 yoast_seo.install
  2. 7 yoast_seo.install

Install, update, and uninstall functions for the Real-Time SEO module.

File

yoast_seo.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Real-Time SEO module.
 */
use Drupal\views\Views;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;

/**
 * Remove the SEO status from the content overview.
 */
function yoast_seo_update_8201() {
  $content_view = Views::getView('content');
  if ($content_view) {
    $display_id = 'page_1';
    $handlers = $content_view
      ->getHandlers('field', $display_id);
    if (isset($handlers['field_yoast_seo'])) {
      $content_view
        ->removeHandler($display_id, 'field', 'field_yoast_seo');
      $content_view
        ->save();
    }
  }
}

/**
 * Add a title and description property to the yoast_seo field.
 */
function yoast_seo_update_8202() {
  $field_type = 'yoast_seo';
  $add_properties = [
    'title',
    'description',
  ];
  $manager = \Drupal::entityDefinitionUpdateManager();
  $field_map = \Drupal::service('entity_field.manager')
    ->getFieldMapByFieldType($field_type);
  foreach ($field_map as $entity_type_id => $fields) {
    foreach (array_keys($fields) as $field_name) {
      $field_storage_definition = $manager
        ->getFieldStorageDefinition($field_name, $entity_type_id);
      $storage = \Drupal::entityTypeManager()
        ->getStorage($entity_type_id);
      if ($storage instanceof SqlContentEntityStorage) {
        $table_mapping = $storage
          ->getTableMapping([
          $field_name => $field_storage_definition,
        ]);
        $table_names = $table_mapping
          ->getDedicatedTableNames();
        $columns = $table_mapping
          ->getColumnNames($field_name);
        foreach ($table_names as $table_name) {
          $field_schema = $field_storage_definition
            ->getSchema();
          $schema = \Drupal::database()
            ->schema();
          foreach ($add_properties as $new_property) {
            $field_exists = $schema
              ->fieldExists($table_name, $columns[$new_property]);
            $table_exists = $schema
              ->tableExists($table_name);
            if (!$field_exists && $table_exists) {
              $schema
                ->addField($table_name, $columns[$new_property], $field_schema['columns'][$new_property]);
            }
          }
        }
      }
      $manager
        ->updateFieldStorageDefinition($field_storage_definition);
    }
  }
}

/**
 * Move score label configuration into module settings.
 */
function yoast_seo_update_8203() {
  \Drupal::configFactory()
    ->getEditable('yoast_seo.settings')
    ->set('score_rules', [
    0 => 'Not available',
    8 => 'Good',
    1 => 'Bad',
    5 => 'Okay',
  ])
    ->save();
}

Functions

Namesort descending Description
yoast_seo_update_8201 Remove the SEO status from the content overview.
yoast_seo_update_8202 Add a title and description property to the yoast_seo field.
yoast_seo_update_8203 Move score label configuration into module settings.