summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2013-10-16 11:21:17 (GMT)
committerNathaniel Catchpole2013-10-16 11:21:17 (GMT)
commit7c219bbfc1edfbe95c9ebe4ddb9ae76a119143f0 (patch)
tree76719d9ed46c3fb7390f2daacae8be3e1ed30f84
parentcc84f3903c16932585c46591f780e54121e8598f (diff)
Issue #2060705 by yched, Hydra, swentel, amateescu: Remove the 'hidden widget' plugin, it is actually never used.
-rw-r--r--core/modules/field/field.module8
-rw-r--r--core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php32
-rw-r--r--core/modules/field/lib/Drupal/field/Tests/FormTest.php19
-rw-r--r--core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php7
4 files changed, 14 insertions, 52 deletions
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index 22d7592..7621595 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -244,14 +244,6 @@ function _field_generate_entity_field_definition(FieldInterface $field, FieldIns
}
/**
- * 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().
*/
function field_entity_bundle_create($entity_type, $bundle) {
diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php b/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php
deleted file mode 100644
index 08b8d16..0000000
--- a/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?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();
- }
-}
diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php
index f9b37d5..6fe20eb 100644
--- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php
+++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php
@@ -578,9 +578,9 @@ class FormTest extends FieldTestBase {
}
/**
- * Tests the Hidden widget.
+ * Tests hiding a field in a form.
*/
- function testFieldFormHiddenWidget() {
+ function testHiddenField() {
$entity_type = 'entity_test_rev';
$field = $this->field_single;
$field['entity_type'] = $entity_type;
@@ -592,18 +592,15 @@ class FormTest extends FieldTestBase {
entity_create('field_entity', $field)->save();
$this->instance = entity_create('field_instance', $this->instance);
$this->instance->save();
- entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default')
- ->setComponent($this->instance->getFieldName(), array(
- 'type' => 'hidden',
- ))
- ->save();
+ // We explicitly do not assign a widget in a form display, so the field
+ // stays hidden in forms.
// Display the entity creation form.
$this->drupalGet($entity_type . '/add');
// Create an entity and test that the default value is assigned correctly to
// 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'));
preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match);
$id = $match[1];
@@ -634,11 +631,9 @@ class FormTest extends FieldTestBase {
$entity = entity_load($entity_type, $id);
$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')
- ->setComponent($this->instance->getFieldName(), array(
- 'type' => 'hidden',
- ))
+ ->removeComponent($this->instance->getFieldName())
->save();
// Create a new revision.
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php
index a60b329..e1df25a 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php
@@ -85,6 +85,13 @@ class FormDisplayOverview extends DisplayOverviewBase {
/**
* {@inheritdoc}
*/
+ protected function getPluginOptions($field_type) {
+ return parent::getPluginOptions($field_type) + array('hidden' => '- ' . t('Hidden') . ' -');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
protected function getDefaultPlugin($field_type) {
return $this->fieldTypes[$field_type]['default_widget'];
}