Verified Commit c0fbd681 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3415412 by dww, gorkagr, acbramley, mstrelan: Field type plugin...

Issue #3415412 by dww, gorkagr, acbramley, mstrelan: Field type plugin description is assumed to be an array
parent ea0ae600
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
field_test_descriptions:
  label: 'Field Test'
  description: 'Fields for testing descriptions.'
+23 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\field_test\Plugin\Field\FieldType;

/**
 * Defines the 'test_field_with_multiple_descriptions' entity field item.
 *
 * @FieldType(
 *   id = "test_field_with_multiple_descriptions",
 *   label = @Translation("Test field (multiple descriptions"),
 *   description = {
 *     @Translation("This multiple line description needs to use an array"),
 *     @Translation("This second line contains important information"),
 *   },
 *   category = "field_test_descriptions",
 *   default_widget = "test_field_widget",
 *   default_formatter = "field_test_default"
 * )
 */
class TestItemWithMultipleDescriptions extends TestItem {
}
+20 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\field_test\Plugin\Field\FieldType;

/**
 * Defines the 'test_field_with_single_description' entity field item.
 *
 * @FieldType(
 *   id = "test_field_with_single_description",
 *   label = @Translation("Test field (single description"),
 *   description = @Translation("This one-line field description is important for testing"),
 *   category = "field_test_descriptions",
 *   default_widget = "test_field_widget",
 *   default_formatter = "field_test_default"
 * )
 */
class TestItemWithSingleDescription extends TestItem {
}
+8 −5
Original line number Diff line number Diff line
@@ -286,15 +286,18 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
          ],
        ];

        foreach ($unique_definitions[$selected_field_type] as $option_key => $option) {
        foreach ($unique_definitions[$selected_field_type] as $option) {
          // If the field type plugin's annotation defines description as an
          // array, render it as an item_list.
          $description = !is_array($option['description']) ? $option['description'] : [
            '#theme' => 'item_list',
            '#items' => $option['description'],
          ];
          $radio_element = [
            '#type' => 'radio',
            '#theme_wrappers' => ['form_element__new_storage_type'],
            '#title' => $option['label'],
            '#description' => [
              '#theme' => 'item_list',
              '#items' => $unique_definitions[$selected_field_type][$option_key]['description'],
            ],
            '#description' => $description,
            '#id' => $option['unique_identifier'],
            '#weight' => $option['weight'],
            '#parents' => ['group_field_options_wrapper'],
+10 −0
Original line number Diff line number Diff line
@@ -136,6 +136,16 @@ public function testAddField() {
      'type' => 'article',
    ]);

    // Make sure field descriptions appear, both 1 line and multiple lines.
    $this->drupalGet('/admin/structure/types/manage/' . $type->id() . '/fields/add-field');
    $edit = [
      'new_storage_type' => 'field_test_descriptions',
    ];
    $this->submitForm($edit, 'Continue');
    $this->assertSession()->pageTextContains('This one-line field description is important for testing');
    $this->assertSession()->pageTextContains('This multiple line description needs to use an array');
    $this->assertSession()->pageTextContains('This second line contains important information');

    // Create a new field without actually saving it.
    $this->fieldUIAddNewField('admin/structure/types/manage/' . $type->id(), 'test_field', 'Test field', 'test_field', [], [], FALSE);
    // Assert that the field was not created.