Verified Commit f1a52222 authored by Dave Long's avatar Dave Long
Browse files

Issue #3372097 by srishtiiee, lauriii, larowlan, longwave, tedbow: Consider...

Issue #3372097 by srishtiiee, lauriii, larowlan, longwave, tedbow: Consider replacing hook_field_type_category_info with YML based plugin discovery
parent 4dcc2b28
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
plain_text:
  label: 'Plain text'
  description: 'Text field that does not support markup.'
  weight: -50
number:
  label: 'Number'
  description: 'Field to store number. I.e. id, price, or quantity.'
  weight: -40
reference:
  label: 'Reference'
  description: 'Field to reference other content.'
  weight: -30
date_time:
  label: 'Date and time'
  description: 'Field to store date and time values.'
  weight: -10
general:
  class: \Drupal\Core\Field\FallbackFieldTypeCategory
+5 −1
Original line number Diff line number Diff line
@@ -744,8 +744,12 @@ services:
  Drupal\Core\Block\BlockManagerInterface: '@plugin.manager.block'
  plugin.manager.field.field_type:
    class: Drupal\Core\Field\FieldTypePluginManager
    arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@typed_data_manager']
    arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@typed_data_manager', '@plugin.manager.field.field_type_category']
  Drupal\Core\Field\FieldTypePluginManagerInterface: '@plugin.manager.field.field_type'
  plugin.manager.field.field_type_category:
    class: \Drupal\Core\Field\FieldTypeCategoryManager
    arguments: [ '%app.root%', '@module_handler', '@cache.discovery' ]
  Drupal\Core\Field\FieldTypeCategoryManagerInterface: '@plugin.manager.field.field_type_category'
  plugin.manager.field.widget:
    class: Drupal\Core\Field\WidgetPluginManager
    arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@plugin.manager.field.field_type']
+22 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Field;

/**
 * Fallback plugin class for FieldTypeCategoryManager.
 */
class FallbackFieldTypeCategory extends FieldTypeCategory {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration) {
    $plugin_definition = [
      'label' => $configuration['label'] ?? '',
      'description' => $configuration['description'] ?? '',
      'weight' => $configuration['weight'] ?? 0,
    ];
    parent::__construct($configuration, $configuration['unique_identifier'], $plugin_definition);
  }

}
+36 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Field;

use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Default object used for field_type_categories plugins.
 *
 * @see \Drupal\Core\Field\FieldTypeCategoryManager
 */
class FieldTypeCategory extends PluginBase implements FieldTypeCategoryInterface {

  /**
   * {@inheritdoc}
   */
  public function getLabel(): TranslatableMarkup {
    return $this->pluginDefinition['label'];
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription(): TranslatableMarkup {
    return $this->pluginDefinition['description'];
  }

  /**
   * {@inheritdoc}
   */
  public function getWeight(): int {
    return $this->pluginDefinition['weight'];
  }

}
+36 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Field;

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides an object that returns the category info about the field type.
 */
interface FieldTypeCategoryInterface {

  /**
   * Returns the field group label.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   The category label.
   */
  public function getLabel(): TranslatableMarkup;

  /**
   * Returns the field group description.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   The category description.
   */
  public function getDescription(): TranslatableMarkup;

  /**
   * Returns the field group weight.
   *
   * @return int
   *   The weight.
   */
  public function getWeight(): int;

}
Loading