Verified Commit 19f5bdd1 authored by Dave Long's avatar Dave Long
Browse files

Issue #3409413 by gorkagr, lauriii, longwave: Error TypeError:...

Issue #3409413 by gorkagr, lauriii, longwave: Error TypeError: Drupal\Core\Field\FieldTypeCategory::getDescription() if a FieldType has 'description' missing in its annotation
parent 09077755
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ class FallbackFieldTypeCategory extends FieldTypeCategory {
  public function __construct(array $configuration, string $plugin_id, array $plugin_definition) {
    $plugin_id = $configuration['unique_identifier'];
    $plugin_definition = [
      'label' => $configuration['label'] ?? '',
      'label' => $configuration['label'],
      'description' => $configuration['description'] ?? '',
      'weight' => $configuration['weight'] ?? 0,
    ] + $plugin_definition;
+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\Core\Field;

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

/**
 * Default object used for field_type_categories plugins.
@@ -15,14 +14,14 @@ class FieldTypeCategory extends PluginBase implements FieldTypeCategoryInterface
  /**
   * {@inheritdoc}
   */
  public function getLabel(): TranslatableMarkup {
  public function getLabel(): string|\Stringable {
    return $this->pluginDefinition['label'];
  }

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

+4 −6
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@

namespace Drupal\Core\Field;

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Provides an object that returns the category info about the field type.
 */
@@ -12,18 +10,18 @@ interface FieldTypeCategoryInterface {
  /**
   * Returns the field group label.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   * @return string|\Stringable
   *   The category label.
   */
  public function getLabel(): TranslatableMarkup;
  public function getLabel(): string|\Stringable;

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

  /**
   * Returns the field group weight.
+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * @FieldType(
 *   id = "test_field",
 *   label = @Translation("Test field"),
 *   description = @Translation("Dummy field type used for tests."),
 *   default_widget = "test_field_widget",
 *   default_formatter = "field_test_default"
 * )
+14 −0
Original line number Diff line number Diff line
@@ -371,4 +371,18 @@ public function testFieldUiDefinitionsAlter() {
    $this->assertSession()->pageTextContains('Boolean (overridden by alter)');
  }

  /**
   * Ensure field category fallback works for field types without a description.
   */
  public function testFieldCategoryFallbackWithoutDescription() {
    $user = $this->drupalCreateUser(['administer node fields']);
    $node_type = $this->drupalCreateContentType();
    $this->drupalLogin($user);
    $this->drupalGet('/admin/structure/types/manage/' . $node_type->id() . '/fields/add-field');
    $field_type = $this->assertSession()->elementExists('xpath', '//label[text()="Test field"]');
    $description_container = $field_type->getParent()->find('css', '.field-option__description');
    $this->assertNotNull($description_container);
    $this->assertEquals('', $description_container->getText());
  }

}