Commit f5679526 authored by Stangl David's avatar Stangl David Committed by George
Browse files

Issue #3149001: Automated Drupal 9 compatibility fixes

parent afdec98b
Loading
Loading
Loading
Loading

composer.json

0 → 100644
+29 −0
Original line number Diff line number Diff line
{
  "name": "drupal/taxonomy_formatter",
  "description": "This is a small module written to provide a custom formatter for taxonomy items",
  "type": "drupal-module",
  "homepage": "https://www.drupal.org/project/taxonomy_formatter",
  "keywords": ["Drupal", "Content", "Content Display", "Fields", "Taxonomy"],
  "license": "GPL-2.0+",
  "minimum-stability": "dev",
  "prefer-stable": true,
  "support": {
    "issues": "https://www.drupal.org/project/issues/taxonomy_formatter",
    "irc": "irc://irc.freenode.org/drupal-contribute",
    "source": "https://www.drupal.org/project/taxonomy_formatter"
  },
  "authors": [
    {
      "name": "Dan Linn",
      "homepage": "https://github.com/danlinn",
      "role": "Maintainer"
    }
  ],
  "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    }
  ],
  "require": { }
}
+50 −56
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains \Drupal\taxonomy_formatter\Plugin\Field\FieldFormatter\TaxonomyTermReferenceCsv.
 */

namespace Drupal\taxonomy_formatter\Plugin\Field\FieldFormatter;

use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\taxonomy\Entity\Term;
use Drupal\Component\Utility\Html;

/**
 * @FieldFormatter(
@@ -42,25 +36,25 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = array();
    $element['links_option'] = array(
    $element = [];
    $element['links_option'] = [
      '#type'           => 'checkbox',
      '#title'          => t('Links'),
      '#description'    => t('When checked terms will be displayed as links'),
      '#title'          => $this->t('Links'),
      '#description'    => $this->t('When checked terms will be displayed as links'),
      '#default_value'  => $this->getSetting('links_option'),
    );
    $element['separator_option'] = array(
    ];
    $element['separator_option'] = [
      '#type'           => 'textfield',
      '#title'          => t('Separator'),
      '#description'    => t('The separator to use, including leading and trailing spaces'),
      '#title'          => $this->t('Separator'),
      '#description'    => $this->t('The separator to use, including leading and trailing spaces'),
      '#default_value'  => $this->getSetting('separator_option'),
    );
    $element['element_option'] = array(
    ];
    $element['element_option'] = [
      '#type'           => 'select',
      '#title'          => t('Element'),
      '#description'    => t('The HTML element to wrap each tag in'),
      '#title'          => $this->t('Element'),
      '#description'    => $this->t('The HTML element to wrap each tag in'),
      '#default_value'  => $this->getSetting('element_option'),
      '#options'        => array(
      '#options'        => [
        '- None -'  => '- None -',
        'span'      => 'span',
        'h1'        => 'h1',
@@ -70,20 +64,20 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
        'h5'        => 'h5',
        'strong'    => 'h6',
        'em'        => 'h7',
      ),
    );
    $element['element_class'] = array(
      ],
    ];
    $element['element_class'] = [
      '#type'           => 'textfield',
      '#title'          => t('Element Class'),
      '#description'    => t('The class assigned to the element'),
      '#title'          => $this->t('Element Class'),
      '#description'    => $this->t('The class assigned to the element'),
      '#default_value'  => $this->getSetting('element_class'),
    );
    $element['wrapper_option'] = array(
    ];
    $element['wrapper_option'] = [
      '#type'           => 'select',
      '#title'          => t('Wrapper'),
      '#description'    => t('The HTML element to wrap the entire collection in'),
      '#title'          => $this->t('Wrapper'),
      '#description'    => $this->t('The HTML element to wrap the entire collection in'),
      '#default_value'  => $this->getSetting('wrapper_option'),
      '#options'        => array(
      '#options'        => [
        '- None -'  => '- None -',
        'div'       => 'div',
        'span'      => 'span',
@@ -95,14 +89,14 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
        'p'         => 'p',
        'strong'    => 'strong',
        'em'        => 'em',
      ),
    );
    $element['wrapper_class'] = array(
      ],
    ];
    $element['wrapper_class'] = [
      '#type'           => 'textfield',
      '#title'          => t('Wrapper Class'),
      '#description'    => t('The class assigned to the wrapper'),
      '#title'          => $this->t('Wrapper Class'),
      '#description'    => $this->t('The class assigned to the wrapper'),
      '#default_value'  => $this->getSetting('wrapper_class'),
    );
    ];
    return $element;
  }

@@ -110,21 +104,21 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = array();
    $summary[] = t('The Terms will be displayed separated by "@separator"', array('@separator' => $this->getSetting('separator_option')));
    $summary = [];
    $summary[] = $this->t('The Terms will be displayed separated by "@separator"', ['@separator' => $this->getSetting('separator_option')]);
    if ($this->getSetting('links_option')) {
      $summary[]= $this->t('<br>The terms will link to the term pages');
      $summary[] = $this->$this->t('<br>The terms will link to the term pages');
    }
    if ($this->getSetting('element_option') != "- None -") {
      $summary[]= t('<br>Elements will be wrapped in a "@element" tag',  array('@element' => $this->getSetting('element_option')));
      if (!empty($settings['element_class'])) {
        $summary[]= t(' with the class of @elemclass', array('@elemclass' => $this->getSetting('element_class')));
      $summary[] = $this->t('<br>Elements will be wrapped in a "@element" tag', ['@element' => $this->getSetting('element_option')]);
      if (!empty($this->getSetting('element_class'))) {
        $summary[] = ' ' . $this->t('with the class of @elemclass', ['@elemclass' => $this->getSetting('element_class')]);
      }
    }
    if ($this->getSetting('wrapper_option') != "- None -") {
      $summary[]= t('<br>The entire list will be wrapped in a "@wrapper" tag', array('@wrapper' => $this->getSetting('wrapper_option')));
      if (!empty($settings['wrapper_class'])) {
        $summary[]= t(' with the class of @wrapclass', array('@wrapclass' => $this->getSetting('wrapper_class')));
      $summary[] = $this->t('<br>The entire list will be wrapped in a "@wrapper" tag', ['@wrapper' => $this->getSetting('wrapper_option')]);
      if (!empty($this->getSetting('wrapper_class'))) {
        $summary[] = ' ' . $this->t('with the class of @wrapclass', ['@wrapclass' => $this->getSetting('wrapper_class')]);
      }
    }
    return $summary;
@@ -135,10 +129,10 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {

    $element = array();
    $separator = SafeMarkup::checkPlain($this->getSetting('separator_option'));
    $element = [];
    $separator = Html::escape($this->getSetting('separator_option'));
    if ($this->getSetting('element_option') != '- None -') {
      $elementwrap[0] = '<' . $this->getSetting('element_option') . ' class="' . SafeMarkup::checkPlain($this->getSetting('element_class')) . '">';
      $elementwrap[0] = '<' . $this->getSetting('element_option') . ' class="' . Html::cleanCssIdentifier($this->getSetting('element_class')) . '">';
      $elementwrap[1] = '</' . $this->getSetting('element_option') . '>';
    }
    else {
@@ -146,7 +140,7 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
      $elementwrap[1] = '';
    }
    if ($this->getSetting('wrapper_option') != '- None -') {
      $wrapper[0] = '<' . $this->getSetting('wrapper_option') . ' class="' . \Drupal\Component\Utility\SafeMarkup::checkPlain($this->getSetting('wrapper_class')) . '">';
      $wrapper[0] = '<' . $this->getSetting('wrapper_option') . ' class="' . Html::cleanCssIdentifier($this->getSetting('wrapper_class')) . '">';
      $wrapper[1] = '</' . $this->getSetting('wrapper_option') . '>';
    }
    else {
@@ -160,7 +154,7 @@ class TaxonomyTermReferenceCsv extends EntityReferenceFormatterBase {
        $formatted .= $elementwrap[0] . $entity->toLink()->toString() . $elementwrap[1] . $separator;
      }
      else {
        $formatted .= $elementwrap[0] . SafeMarkup::checkPlain($entity->label()) . $elementwrap[1] . $separator;
        $formatted .= $elementwrap[0] . Html::escape($entity->label()) . $elementwrap[1] . $separator;
      }
    }
    $length = strlen($separator);
+1 −1
Original line number Diff line number Diff line
name: 'Taxonomy Formatter'
description: 'Add a formatter to taxonomy terms that allows selection of element type, wrapper type, and separators.'
package: Fields
core: 8.x
core_version_requirement: ^8.8 || ^9
type: module
dependencies:
  - drupal:taxonomy
+1 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Adds a formatter for taxonomy terms with options to specify element type, wrapper type, and separators.