Commit 7c219bbf authored by catch's avatar catch

Issue #2060705 by yched, Hydra, swentel, amateescu: Remove the 'hidden widget'...

Issue #2060705 by yched, Hydra, swentel, amateescu: Remove the 'hidden widget' plugin, it is actually never used.
parent cc84f390
...@@ -243,14 +243,6 @@ function _field_generate_entity_field_definition(FieldInterface $field, FieldIns ...@@ -243,14 +243,6 @@ function _field_generate_entity_field_definition(FieldInterface $field, FieldIns
return $definition; return $definition;
} }
/**
* Implements hook_field_widget_info_alter().
*/
function field_field_widget_info_alter(&$info) {
// Add the Hidden widget to all field types.
$info['hidden']['field_types'] = array_keys(\Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions());
}
/** /**
* Implements hook_entity_bundle_create(). * Implements hook_entity_bundle_create().
*/ */
......
<?php
/**
* @file
* Contains \Drupal\field\Plugin\field\widget\HiddenWidget.
*/
namespace Drupal\field\Plugin\field\widget;
use Drupal\Core\Entity\Field\FieldItemListInterface;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'Hidden' widget.
*
* @FieldWidget(
* id = "hidden",
* label = @Translation("- Hidden -"),
* multiple_values = TRUE,
* weight = 50
* )
*/
class HiddenWidget extends WidgetBase {
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) {
// The purpose of this widget is to be hidden, so nothing to do here.
return array();
}
}
...@@ -578,9 +578,9 @@ function testFieldFormAccess() { ...@@ -578,9 +578,9 @@ function testFieldFormAccess() {
} }
/** /**
* Tests the Hidden widget. * Tests hiding a field in a form.
*/ */
function testFieldFormHiddenWidget() { function testHiddenField() {
$entity_type = 'entity_test_rev'; $entity_type = 'entity_test_rev';
$field = $this->field_single; $field = $this->field_single;
$field['entity_type'] = $entity_type; $field['entity_type'] = $entity_type;
...@@ -592,18 +592,15 @@ function testFieldFormHiddenWidget() { ...@@ -592,18 +592,15 @@ function testFieldFormHiddenWidget() {
entity_create('field_entity', $field)->save(); entity_create('field_entity', $field)->save();
$this->instance = entity_create('field_instance', $this->instance); $this->instance = entity_create('field_instance', $this->instance);
$this->instance->save(); $this->instance->save();
entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') // We explicitly do not assign a widget in a form display, so the field
->setComponent($this->instance->getFieldName(), array( // stays hidden in forms.
'type' => 'hidden',
))
->save();
// Display the entity creation form. // Display the entity creation form.
$this->drupalGet($entity_type . '/add'); $this->drupalGet($entity_type . '/add');
// Create an entity and test that the default value is assigned correctly to // Create an entity and test that the default value is assigned correctly to
// the field that uses the hidden widget. // the field that uses the hidden widget.
$this->assertNoField("{$field_name}[0][value]", 'The hidden widget is not displayed'); $this->assertNoField("{$field_name}[0][value]", 'The field does not appear in the form');
$this->drupalPostForm(NULL, array('user_id' => 1, 'name' => $this->randomName()), t('Save')); $this->drupalPostForm(NULL, array('user_id' => 1, 'name' => $this->randomName()), t('Save'));
preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match); preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match);
$id = $match[1]; $id = $match[1];
...@@ -634,11 +631,9 @@ function testFieldFormHiddenWidget() { ...@@ -634,11 +631,9 @@ function testFieldFormHiddenWidget() {
$entity = entity_load($entity_type, $id); $entity = entity_load($entity_type, $id);
$this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated'); $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated');
// Update the form display and switch to the Hidden widget again. // Set the field back to hidden.
entity_get_form_display($entity_type, $this->instance->bundle, 'default') entity_get_form_display($entity_type, $this->instance->bundle, 'default')
->setComponent($this->instance->getFieldName(), array( ->removeComponent($this->instance->getFieldName())
'type' => 'hidden',
))
->save(); ->save();
// Create a new revision. // Create a new revision.
......
...@@ -82,6 +82,13 @@ protected function getPlugin($instance, $configuration) { ...@@ -82,6 +82,13 @@ protected function getPlugin($instance, $configuration) {
return $plugin; return $plugin;
} }
/**
* {@inheritdoc}
*/
protected function getPluginOptions($field_type) {
return parent::getPluginOptions($field_type) + array('hidden' => '- ' . t('Hidden') . ' -');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment