Verified Commit ea3f7b53 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3347291 by lauriii, srishtiiee, tim.plunkett, hooroomoo, narendraR,...

Issue #3347291 by lauriii, srishtiiee, tim.plunkett, hooroomoo, narendraR, tedbow, bnjmnm, alexpott, Berdir: Combine field storage and field instance forms
parent ce2e1aa2
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\TypedData\FieldItemDataDefinition;
use Drupal\field\Entity\FieldStorageConfig;

/**
 * Base class for configurable field definitions.
@@ -475,11 +474,6 @@ public function __sleep() {
    // recalculated.
    unset($properties['itemDefinition'], $properties['original']);

    // Field storage can be recalculated if it's not new.
    if (array_key_exists('fieldStorage', $properties) && $properties['fieldStorage'] instanceof FieldStorageConfig && !$properties['fieldStorage']->isNew()) {
      unset($properties['fieldStorage']);
    }

    return array_keys($properties);
  }

+18 −3
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ class SubformState extends FormStateDecoratorBase implements SubformStateInterfa
   *   The subform's parent form.
   * @param \Drupal\Core\Form\FormStateInterface $parent_form_state
   *   The parent form state.
   * @param \Drupal\Core\Form\FormInterface|null $subformFormObject
   *   The subform form object when it's not the same as the parent form.
   */
  protected function __construct(array &$subform, array &$parent_form, FormStateInterface $parent_form_state) {
  protected function __construct(array &$subform, array &$parent_form, FormStateInterface $parent_form_state, protected readonly ?FormInterface $subformFormObject = NULL) {
    $this->decoratedFormState = $parent_form_state;
    $this->parentForm = $parent_form;
    $this->subform = $subform;
@@ -50,11 +52,13 @@ protected function __construct(array &$subform, array &$parent_form, FormStateIn
   *   The subform's parent form.
   * @param \Drupal\Core\Form\FormStateInterface $parent_form_state
   *   The parent form state.
   * @param \Drupal\Core\Form\FormInterface|null $subform_form_object
   *   The subform form object when it's not the same as the parent form.
   *
   * @return static
   */
  public static function createForSubform(array &$subform, array &$parent_form, FormStateInterface $parent_form_state) {
    return new static($subform, $parent_form, $parent_form_state);
  public static function createForSubform(array &$subform, array &$parent_form, FormStateInterface $parent_form_state, ?FormInterface $subform_form_object = NULL) {
    return new static($subform, $parent_form, $parent_form_state, $subform_form_object);
  }

  /**
@@ -151,4 +155,15 @@ public function setErrorByName($name, $message = '') {
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getFormObject() {
    if ($this->subformFormObject) {
      return $this->subformFormObject;
    }

    return parent::getFormObject();
  }

}
+4 −5
Original line number Diff line number Diff line
@@ -162,8 +162,7 @@ public function testCommentFieldCreate() {

    // Try to save the comment field without selecting a comment type.
    $edit = [];
    $this->drupalGet('admin/config/people/accounts/add-storage/user/field_user_comment');
    $this->submitForm($edit, 'Continue');
    $this->submitForm($edit, 'Update settings');
    // We should get an error message.
    $this->assertSession()->pageTextContains('The submitted value in the Comment type element is not allowed.');

@@ -178,10 +177,10 @@ public function testCommentFieldCreate() {

    // Select a comment type and try to save again.
    $edit = [
      'settings[comment_type]' => 'user_comment_type',
      'field_storage[subform][settings][comment_type]' => 'user_comment_type',
    ];
    $this->drupalGet('admin/config/people/accounts/add-storage/user/field_user_comment');
    $this->submitForm($edit, 'Continue');
    $this->drupalGet('admin/config/people/accounts/add-field/user/field_user_comment');
    $this->submitForm($edit, 'Update settings');
    // We shouldn't get an error message.
    $this->assertSession()->pageTextNotContains('The submitted value in the Comment type element is not allowed.');

+1 −3
Original line number Diff line number Diff line
@@ -277,8 +277,6 @@ public function testCommentFunctionality() {
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldNotExists('edit-default-value-input-comment-und-0-status-0');
    // Test that field to change cardinality is not available.
    $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment/storage');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldNotExists('cardinality_number');
    $this->assertSession()->fieldNotExists('cardinality');

@@ -439,7 +437,7 @@ public function testCommentFunctionality() {

    // Add a new comment field.
    $storage_edit = [
      'settings[comment_type]' => 'foobar',
      'field_storage[subform][settings][comment_type]' => 'foobar',
    ];
    $this->fieldUIAddNewField('entity_test/structure/entity_test', 'foobar', 'Foobar', 'comment', $storage_edit);

+2 −2
Original line number Diff line number Diff line
@@ -932,8 +932,8 @@ public function testDateStorageSettings() {
    ];
    $this->drupalGet('node/add/date_content');
    $this->submitForm($edit, 'Save');
    $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage');
    $this->assertSession()->elementsCount('xpath', "//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]", 1);
    $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name);
    $this->assertSession()->elementsCount('xpath', "//*[@name='field_storage[subform][settings][datetime_type]' and contains(@disabled, 'disabled')]", 1);
  }

}
Loading