diff --git a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php index b4a8565..4b8de0a 100644 --- a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php +++ b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php @@ -28,18 +28,13 @@ class CommentWidget extends WidgetBase { * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) { - $field = $this->fieldDefinition; - $entity = $items->getParent(); - - // Get default value from the field instance. - $field_default_values = $this->fieldDefinition->getDefaultValue($entity); - $status = $items->status; + $entity = $items->getEntity(); $element['status'] = array( '#type' => 'radios', '#title' => t('Comments'), '#title_display' => 'invisible', - '#default_value' => $status, + '#default_value' => $items->status, '#options' => array( CommentItemInterface::OPEN => t('Open'), CommentItemInterface::CLOSED => t('Closed'), @@ -58,7 +53,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // If the entity doesn't have any comments, the "hidden" option makes no // sense, so don't even bother presenting it to the user unless this is the // default value widget on the field settings form. - if ($element['#field_parents'] != array('default_value_input') && !$entity->get($field->getName())->comment_count) { + if ($element['#field_parents'] != array('default_value_input') && !$items->comment_count) { $element['status'][CommentItemInterface::HIDDEN]['#access'] = FALSE; // Also adjust the description of the "closed" option. $element['status'][CommentItemInterface::CLOSED]['#description'] = t('Users cannot post comments.'); @@ -67,6 +62,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // second column on wide-resolutions), place the field as a details element // in this tab-set. if (isset($form['advanced'])) { + // Get default value from the field instance. + $field_default_values = $this->fieldDefinition->getDefaultValue($entity); + $element += array( '#type' => 'details', // Open the details when the selected value is different to the stored @@ -74,7 +72,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#open' => ($items->status != $field_default_values[0]['status']), '#group' => 'advanced', '#attributes' => array( - 'class' => array('comment-' . drupal_html_class($element['#entity_type']) . '-settings-form'), + 'class' => array('comment-' . drupal_html_class($entity->getEntityTypeId()) . '-settings-form'), ), '#attached' => array( 'library' => array('comment/drupal.comment'), diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index 819e389..255c19d 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -540,7 +540,6 @@ function testFieldFormAccess() { $form_state = form_state_defaults(); $display->buildForm($entity, $form, $form_state); - $this->assertEqual($form[$field_name_no_access]['widget'][0]['value']['#entity_type'], $entity_type, 'The correct entity type is set in the field structure.'); $this->assertFalse($form[$field_name_no_access]['#access'], 'Field #access is FALSE for the field without edit access.'); // Display creation form. diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index 98ca97a..c710283 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -159,8 +159,8 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f $elements['#title'] = $title; $elements['#description'] = $description; - $elements['#field_name'] = $element['#field_name']; - $elements['#language'] = $element['#language']; + $elements['#field_name'] = $field_name; + $elements['#language'] = $items->getLangcode(); $elements['#display_field'] = (bool) $this->getFieldSetting('display_field'); // The field settings include defaults for the field type. However, this // widget is a base class for other widgets (e.g., ImageWidget) that may diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 4541ba5..2f51a4c 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -87,6 +87,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Post-process the title field to make it conditionally required if URL is // non-empty. Omit the validation on the field edit form, since the field // settings cannot be saved otherwise. + // @todo $is_field_edit_form = ($element['#entity'] === NULL); if (!$is_field_edit_form && $this->getFieldSetting('title') == DRUPAL_REQUIRED) { $element['#element_validate'][] = array($this, 'validateTitle');