Commit 0e9efbfa authored by Damien McKenna's avatar Damien McKenna
Browse files

Issue #2864079 by DamienMcKenna: Resolve coding standards violations.

parent 35779bf4
Loading
Loading
Loading
Loading
+1
Changes for CHANGELOG.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ Metatag 8.x-1.x-dev, xxxx-xx-xx
-------------------------------
#2882769 by DamienMcKenna: Added a hook_requirements() message about the
  Schema.org Metatag module.
#2864079 by DamienMcKenna: Resolve coding standards violations.


Metatag 8.x-1.3, 2017-09-29
+20 −20
Changes for metatag.install: 20 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -28,7 +28,11 @@ function metatag_requirements($phase) {
        'severity' => REQUIREMENT_INFO,
        'title' => 'Metatag',
        'value' => t('Schema.org Metatag is recommended'),
        'description' => t('The <a href="@module">Schema.org Metatag</a> module is highly recommended to add <a href="@jsonld">JSON-LD</a> -formatted <a href="@schema">schema.org</a> compatible data structures to the site.', ['@module' => 'https://www.drupal.org/project/schema_metatag', '@jsonld' => 'https://json-ld.org', '@schema' => 'http://schema.org']),
        'description' => t('The <a href="@module">Schema.org Metatag</a> module is highly recommended to add <a href="@jsonld">JSON-LD</a> -formatted <a href="@schema">schema.org</a> compatible data structures to the site.', [
          '@module' => 'https://www.drupal.org/project/schema_metatag',
          '@jsonld' => 'https://json-ld.org',
          '@schema' => 'http://schema.org',
        ]),
      ];
    }
    else {
@@ -36,7 +40,9 @@ function metatag_requirements($phase) {
        'severity' => REQUIREMENT_OK,
        'title' => 'Metatag',
        'value' => t('Schema.org Metatag is installed'),
        'description' => t('The <a href="@module">Schema.org Metatag</a> module is installed.', ['@module' => 'https://www.drupal.org/project/schema_metatag']),
        'description' => t('The <a href="@module">Schema.org Metatag</a> module is installed.', [
          '@module' => 'https://www.drupal.org/project/schema_metatag',
        ]),
      ];
    }
  }
@@ -72,8 +78,8 @@ function metatag_update_8101() {
      $field_default_tags = unserialize($field_default_tags_value);

      // Determine the table and "value" field names.
      $field_table = "node__$field_name";
      $field_value_field = "$field_name" . "_value";
      $field_table = "node__" . $field_name;
      $field_value_field = $field_name . "_value";

      // Delete all records where the field value and default are identical.
      \Drupal::database()->delete($field_table)
@@ -126,8 +132,8 @@ function metatag_update_8102(&$sandbox) {
        $field_default_tags = unserialize($field_default_tags_value);

        // Determine the table and "value" field names.
        $field_table = "node__$field_name";
        $field_value_field = "$field_name" . "_value";
        $field_table = "node__" . $field_name;
        $field_value_field = $field_name . "_value";

        // Get all records where the field data does not match the default.
        $query = \Drupal::database()->select($field_table);
@@ -211,20 +217,20 @@ function metatag_update_8102(&$sandbox) {
      $current_record++;
    }

    // We ran out of records for the field so start the next batch out with the
    // next field.
    if (!isset($current_field_records[$current_record])) {
      // We ran out of records for the field so start the next batch out with
      // the next field.
      $current_field++;
      $current_record = 0;
    }

    if (!isset($sandbox['fields'][$current_field])) {
    // We have finished all the fields. All done.
    if (!isset($sandbox['fields'][$current_field])) {
      $sandbox['records_processed'] += $counter - 1;
      $sandbox['#finished'] = 1;
    }
    else {
    // Update the sandbox values to prepare for the next round.
    else {
      $sandbox['current_field'] = $current_field;
      $sandbox['current_record'] = $current_record;
      $sandbox['records_processed'] += $counter - 1;
@@ -235,7 +241,7 @@ function metatag_update_8102(&$sandbox) {
  if ($sandbox['total_records'] > 0) {
    return (string) t('Processed @processed of @total overridden Metatag records.', [
      '@processed' => $sandbox['records_processed'],
      '@total' => $sandbox['total_records']
      '@total' => $sandbox['total_records'],
    ]);
  }
  else {
@@ -250,9 +256,7 @@ function metatag_update_8103() {
  $config_installer = \Drupal::service('config.installer');
  $entity_manager = \Drupal::entityTypeManager();

  /**
   * 1. Install cofiguration.
   */
  // 1. Install cofiguration.
  $sync_status = $config_installer->isSyncing();
  if ($sync_status) {
    $source_storage = $config_installer->getSourceStorage();
@@ -273,9 +277,7 @@ function metatag_update_8103() {
  // Apply all entity definition changes.
  \Drupal::entityDefinitionUpdateManager()->applyUpdates();

  /**
   * 2. Extract Metatag field defaults.
   */
  // 2. Extract Metatag field defaults.
  $entity_info = $entity_manager->getDefinitions();
  $tags = [];

@@ -311,9 +313,7 @@ function metatag_update_8103() {
    }
  }

  /**
   * 3. Create Config entities with field default values.
   */
  // 3. Create Config entities with field default values.
  if (!empty($tags)) {
    $bundleInfoManager = \Drupal::service('entity_type.bundle.info');
    foreach ($tags as $metatag_defaults_id => $values) {
−1
Changes for metatag.links.action.yml: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,4 +3,3 @@ entity.metatag_defaults.add_form:
  title: 'Add default meta tags'
  appears_on:
    - entity.metatag_defaults.collection
+28 −28
Changes for metatag.module: 28 added lines, 28 removed lines.
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ function metatag_help($route_name, RouteMatchInterface $route_match) {
      $output .= '<li>' . t('To override the meta tags for individual entities, e.g. for individual nodes, add the "Metatag" field via the field settings for that entity or bundle type.') . '</li>';
      $output .= '</ol>';
      return $output;
      break;

    // The main configuration page.
    case 'entity.metatag_defaults.collection':
@@ -44,14 +43,12 @@ function metatag_help($route_name, RouteMatchInterface $route_match) {
      $output .= '<p>' . t('If the top-level configuration is not specific enough, additional default meta tag configurations can be added for a specific entity type or entity bundle, e.g. for a specific content type.') . '</p>';
      $output .= '<p>' . t('Meta tags can be further refined on a per-entity basis, e.g. for individual nodes, by adding the "Metatag" field to that entity type through its normal field settings pages.') . '</p>';
      return $output;
      break;

    // The 'add default meta tags' configuration page.
    case 'entity.metatag_defaults.add_form':
      $output = '<p>' . t('Use the following form to override the global default meta tags for a specific entity type or entity bundle. In practical terms, this allows the meta tags to be customized for a specific content type or taxonomy vocabulary, so that its content will have different meta tags <em>default values</em> than others.') . '</p>';
      $output .= '<p>' . t('As a reminder, if the "Metatag" field is added to the entity type through its normal field settings, the meta tags can be further refined on a per entity basis; this allows each node to have its meta tags  customized on an individual basis.') . '</p>';
      return $output;
      break;
  }
}

@@ -132,6 +129,7 @@ function metatag_page_attachments(array &$attachments) {
    }
  }
}

/**
 * Implements hook_module_implements_alter().
 */
@@ -193,7 +191,7 @@ function _metatag_remove_duplicate_entity_tags(array &$build) {
    // tag.
    if (isset($metatag_attachments['#attached']['html_head'])) {
      foreach ($metatag_attachments['#attached']['html_head'] as $metatag_item) {
        if (in_array($metatag_item[1], array('canonical_url', 'shortlink'))) {
        if (in_array($metatag_item[1], ['canonical_url', 'shortlink'])) {
          // Metatag provides rel="canonical" and/or rel="shortlink" tags.
          foreach ($build['#attached']['html_head_link'] as $key => $item) {
            if (isset($item[0]['rel']) && in_array($item[0]['rel'], ['canonical', 'shortlink'])) {
@@ -233,7 +231,7 @@ function metatag_is_current_route_supported() {
/**
 * Returns the entity of the current route.
 *
 * @return EntityInterface
 * @return Drupal\Core\Entity\EntityInterface
 *   The entity or NULL if this is not an entity route.
 */
function metatag_get_route_entity() {
@@ -248,16 +246,16 @@ function metatag_get_route_entity() {
    return $route_match->getParameter($entity_type);
  }

  // Look for a rest entity view page, e.g. node/{nid}?_format=json, etc.
  // Look for a rest entity view page, e.g. "node/{nid}?_format=json", etc.
  $matches = [];
  // ie: rest.entity.node.GET.json
  // Matches e.g. "rest.entity.node.GET.json".
  preg_match('/rest\.entity\.(.*)\.(.*)\.(.*)/', $route_name, $matches);
  if (!empty($matches[1])) {
    $entity_type = $matches[1];
    return $route_match->getParameter($entity_type);
  }

  // Look for entity object 'add' pages, e.g. node/add/{bundle}.
  // Look for entity object 'add' pages, e.g. "node/add/{bundle}".
  $route_name_matches = [];
  preg_match('/(entity\.)?(.*)\.add(_form)?/', $route_name, $route_name_matches);
  if (!empty($route_name_matches[2])) {
@@ -275,7 +273,7 @@ function metatag_get_route_entity() {
    }
  }

  // Look for entity object 'edit' pages, e.g. node/{entity_id}/edit.
  // Look for entity object 'edit' pages, e.g. "node/{entity_id}/edit".
  $route_name_matches = [];
  preg_match('/entity\.(.*)\.edit_form/', $route_name, $route_name_matches);
  if (!empty($route_name_matches[1])) {
@@ -290,7 +288,7 @@ function metatag_get_route_entity() {
  }

  // Look for entity object 'add content translation' pages, e.g.
  // node/{nid}/translations/add/{source_lang}/{translation_lang}
  // "node/{nid}/translations/add/{source_lang}/{translation_lang}".
  $route_name_matches = [];
  preg_match('/(entity\.)?(.*)\.content_translation_add/', $route_name, $route_name_matches);
  if (!empty($route_name_matches[2])) {
@@ -361,8 +359,10 @@ function metatag_preprocess_html(&$variables) {
        $variables['head_title'] = [];
        $variables['head_title']['title'] = html_entity_decode($attachment[0]['#attributes']['content'], ENT_QUOTES);
        // Original:
        // $variables['head_title_array']['title'] = $attachment[0]['#attributes']['content'];
        // $variables['head_title'] = implode(' | ', $variables['head_title_array']);
        // $variables['head_title_array']['title'] =
        //   $attachment[0]['#attributes']['content'];
        // $variables['head_title'] = implode(' | ',
        //   $variables['head_title_array']);
        break;
      }
    }
@@ -463,8 +463,8 @@ function metatag_entity_base_field_info(EntityTypeInterface $entity_type) {
    'Drupal\comment\Entity\Comment',
  ];

  // If the entity type doesn't have a base table, has no link template then there's no point in
  // supporting it.
  // If the entity type doesn't have a base table, has no link template then
  // there's no point in supporting it.
  if (!empty($base_table) && $canonical_template_exists && !in_array($original_class, $classes_to_skip)) {
    $fields['metatag'] = BaseFieldDefinition::create('map')
      ->setLabel(t('Metatags'))
@@ -483,24 +483,24 @@ function metatag_entity_base_field_info(EntityTypeInterface $entity_type) {
 */
function metatag_entity_diff_options($entity_type) {
  if (metatag_entity_supports_metatags($entity_type)) {
    $options = array(
    $options = [
      'metatag' => t('Metatags'),
    );
    ];
    return $options;
  }
}

/**
 * Implements hook_entity_diff
 * Implements hook_entity_diff().
 */
function metatag_entity_diff($old_entity, $new_entity, $context) {
  $result = array();
  $result = [];
  $entity_type = $context['entity_type'];
  $options = variable_get('diff_additional_options_' . $entity_type, array());
  $options = variable_get('diff_additional_options_' . $entity_type, []);
  if (!empty($options['metatag']) && metatag_entity_supports_metatags($entity_type)) {
    // Find metatags that are set on either the new or old entity.
    $tags = array();
    foreach (array('old' => $old_entity, 'new' => $new_entity) as $entity_key => $entity) {
    $tags = [];
    foreach (['old' => $old_entity, 'new' => $new_entity] as $entity_key => $entity) {
      $language = metatag_entity_get_language($entity_type, $entity);
      if (isset($entity->metatags[$language])) {
        foreach ($entity->metatags[$language] as $key => $value) {
@@ -512,16 +512,16 @@ function metatag_entity_diff($old_entity, $new_entity, $context) {
    $init_weight = 100;
    foreach ($tags as $key => $values) {
      $id = ucwords('Meta ' . $key);
      // @todo find the default values and show these if not set.
      $result[$id] = array(
      // @todo Find the default values and show these if not set.
      $result[$id] = [
        '#name' => $id,
        '#old' => array(empty($values['old']) ? '' : $values['old']),
        '#new' => array(empty($values['new']) ? '' : $values['new']),
        '#old' => [empty($values['old']) ? '' : $values['old']],
        '#new' => [empty($values['new']) ? '' : $values['new']],
        '#weight' => $init_weight++,
        '#settings' => array(
        '#settings' => [
          'show_header' => TRUE,
        ),
      );
        ],
      ];
    }
  }
  return $result;
+3 −4
Changes for metatag_app_links/src/Tests/MetatagAppLinksTagsTest.php: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\metatag_app_links\Tests;

use Drupal\simpletest\WebTestBase;
use Drupal\metatag\Tests\MetatagTagsTestBase;

/**
@@ -15,7 +14,7 @@ class MetatagAppLinksTagsTest extends MetatagTagsTestBase {
  /**
   * {@inheritdoc}
   */
  public $tags = [
  private $tags = [
    'al_android_app_name',
    'al_android_class',
    'al_android_package',
@@ -45,7 +44,7 @@ class MetatagAppLinksTagsTest extends MetatagTagsTestBase {
  /**
   * {@inheritdoc}
   */
  public $test_name_attribute = 'property';
  private $testNameAttribute = 'property';

  /**
   * {@inheritdoc}
@@ -58,7 +57,7 @@ class MetatagAppLinksTagsTest extends MetatagTagsTestBase {
  /**
   * Each of these meta tags has a different tag name vs its internal name.
   */
  public function getTestTagName($tag_name) {
  private function getTestTagName($tag_name) {
    $tag_name = str_replace('al_android_', 'al:android:', $tag_name);
    $tag_name = str_replace('al_ios_', 'al:ios:', $tag_name);
    $tag_name = str_replace('al_ipad_', 'al:ipad:', $tag_name);
Loading