CommentFileSizeAuthor
#107 interdiff-103-106.txt1.32 KBsmiletrl
#107 drupal_options_field_type-2015689-106.patch40.19 KBsmiletrl
#104 interdiff-100-103.txt1.22 KBsmiletrl
#104 drupal_options_field_type-2015689-103.patch40.11 KBsmiletrl
#102 interdiff-97-100.txt2.75 KBsmiletrl
#102 drupal_options_field_type-2015689-100.patch40.09 KBsmiletrl
#97 interdiff-94-97.txt1.02 KBsmiletrl
#97 drupal_options_field_type-2015689-97.patch40.42 KBsmiletrl
#94 interdiff.txt2.16 KBeffulgentsia
#94 drupal_options_field_type-2015689-93.patch40.43 KBeffulgentsia
#92 interdiff.txt1.73 KBeffulgentsia
#92 drupal_options_field_type-2015689-92.patch40.48 KBeffulgentsia
#91 interdiff.txt7.67 KBeffulgentsia
#91 drupal_options_field_type-2015689-91.patch40.12 KBeffulgentsia
#90 interdiff.txt5.06 KBeffulgentsia
#90 drupal_options_field_type-2015689-90.patch39.26 KBeffulgentsia
#87 interdiff-80-87.txt796 bytessmiletrl
#87 drupal_options_field_type-2015689-87.patch39.38 KBsmiletrl
#80 interdiff-77-80.txt3.03 KBsmiletrl
#80 drupal_options_field_type-2015689-80.patch39.37 KBsmiletrl
#77 interdiff-77.txt1.66 KBmradcliffe
#77 2015689-drupal-options-field-type-77.patch41.01 KBmradcliffe
#74 interdiff.txt5.07 KBmradcliffe
#74 2015689-drupal-options-field-type-74.patch41.02 KBmradcliffe
#72 2015689-drupal-options-field-type-72.patch40.96 KBmradcliffe
#68 interdiff.txt3.6 KBmradcliffe
#68 2015689-drupal-options-field-type-68.patch40.9 KBmradcliffe
#66 2015689-drupal-options-field-type-66.patch39.87 KBmradcliffe
#64 interdiff-60-64.txt1.31 KBmradcliffe
#64 options_field_type-2015689-64.patch39.81 KBmradcliffe
#61 interdiff-57-59.patch5.5 KBmradcliffe
#60 allowed_values_verbose_description.png67.92 KBmradcliffe
#60 options_field_type-2015689-59.patch39.81 KBmradcliffe
#57 options_field_type-2015689-57.patch39.9 KBmradcliffe
#51 options_field_type-2015689-51.patch40.27 KBsmiletrl
#51 interdiff-50-51.txt2.8 KBsmiletrl
#50 options_field_type-2015689-50.patch40.37 KBsmiletrl
#50 interdiff-45-50.txt1.79 KBsmiletrl
#45 options_field_type-2015689-45.patch40.35 KBsmiletrl
#45 interdiff-44-45.txt793 bytessmiletrl
#44 options_field_type-2015689-44.patch40.19 KBsmiletrl
#44 interdiff-42-44.txt1.21 KBsmiletrl
#44 interdiff-36-44.txt5.71 KBsmiletrl
#42 options_field_type-2015689-42.patch40.06 KBsmiletrl
#42 interdiff-40-42.txt1006 bytessmiletrl
#40 options_field_type-2015689-40.patch40.07 KBsmiletrl
#40 interdiff-36-40.txt5.58 KBsmiletrl
#36 drupal-convert-field-type-to-typed-data-plugin-options-2015689-36.patch39.67 KBstevector
#36 interdiff.txt4.83 KBstevector
#34 drupal-convert-field-type-to-typed-data-plugin-options-2015689-34.patch39.88 KBjsacksick
#34 interdiff-2015689-30-34.txt9.49 KBjsacksick
#30 Change_test_field_cardinality_to_2.patch678 bytessmiletrl
#29 drupal-convert-field-type-to-typed-data-plugin-options-2015689-29.patch40.9 KBjsacksick
#29 interdiff-2015689-27-29.txt711 bytesjsacksick
#27 drupal-convert-field-type-to-typed-data-plugin-options-2015689-27.patch40.96 KBjsacksick
#27 interdiff-2015689-24-27.txt1.44 KBjsacksick
#24 interdiff-2015689-22-24.txt822 bytesjsacksick
#24 drupal-convert-field-type-to-typed-data-plugin-options-2015689-24.patch40.97 KBjsacksick
#22 drupal-convert-field-type-to-typed-data-plugin-options-2015689-22.patch40.97 KBjsacksick
#22 interdiff-2015689-20-22.txt4.91 KBjsacksick
#20 drupal-convert-field-type-to-typed-data-plugin-options-2015689-20.patch40.86 KBjsacksick
#19 drupal-convert-field-type-to-typed-data-plugin-options-2015689-18.patch40.98 KBjsacksick
#16 drupal-convert-field-type-to-typed-data-plugin-options-2015689-16.patch40.58 KBjsacksick
#11 drupal-convert-field-type-to-typed-data-plugin-options-2015689-11.patch36.67 KBjsacksick
#8 Convert-field-type-to-typed-data-plugin-for-options-module-2015689-8.patch14.56 KBAnonymous (not verified)
#8 interdiff-5-8.txt4.17 KBAnonymous (not verified)
#5 Convert-field-type-to-typed-data-plugin-for-options-module-2015689-5.patch14.22 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

swentel’s picture

Title: Convert field type to data plugin for options module » Convert field type to typed data plugin for options module
swentel’s picture

Status: Postponed » Active
Anonymous’s picture

ok Taking this one

Anonymous’s picture

Assigned: Unassigned »
Anonymous’s picture

Status: Active » Needs review
FileSize
14.22 KB

Go testbot go ! to test my first patch.

swentel’s picture

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/CListBooleanItem.phpundefined
@@ -0,0 +1,13 @@
+class CListBooleanItem extends CFieldItemBase { }

This can't be right, should be ConfigFieldItemBase.

Status: Needs review » Needs work
Anonymous’s picture

Status: Needs work » Needs review
FileSize
4.17 KB
14.56 KB

Added the suggested changes of #6.Please needs review

Status: Needs review » Needs work
Anonymous’s picture

Need Help into this.How to make my patch green ?

jsacksick’s picture

Status: Needs work » Needs review
FileSize
36.67 KB

Here's a new patch, we still have to convert the hook_field_validate() but I wanted to get inputs on the attached patch before I continue to work more on that.
The patch coming from #1848570: Upgrade to Doctrine\Common 2.4 is needed, otherwise you'll get a Doctrine\Common\Annotations\AnnotationException.

Status: Needs review » Needs work
amateescu’s picture

I just want to note that the allowed values stuff will change very soon in #1758622: Provide the options list of an entity field.

smiletrl’s picture

Status: Needs work » Needs review
Issue tags: -Field API

Status: Needs review » Needs work
Issue tags: +Field API
jsacksick’s picture

Assigned: » jsacksick
Status: Needs work » Needs review
FileSize
40.58 KB

This new patch now contains the hook_field_validate() conversion, in order to do that I had to create a new ChoiceConstraint validation class. Hope this one will pass the tests.

Status: Needs review » Needs work
smiletrl’s picture

Good start:) Some suggestions

1). Extra whitesapce
drupal-convert-field-type-to-typed-data-plugin-options-2015689-16.patch:551: trailing whitespace.
drupal-convert-field-type-to-typed-data-plugin-options-2015689-16.patch:653: trailing whitespace.

2).

+    $settings = $field['settings'];
+
+    if ($field['type'] == 'list_boolean') {

I think if is unnecessary here, since this class is for field type list_boolean.

3). '#element_validate' => array(array($this, 'validateAllowedValues')), should use 'property_constraints' => array() too?

jsacksick’s picture

Status: Needs work » Needs review
FileSize
40.98 KB

I had to copy the flattenOptions() method from OptionsWidgetBase because the options_array_flatten function has been removed, we should probably put it back, otherwise we'll have to copy it everytime we need it...

jsacksick’s picture

The attached patch removes the whitespaces + the field type condition.

amateescu’s picture

+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ChoiceConstraint.php
@@ -0,0 +1,38 @@
+ * @todo: Move this below the TypedData core component.

This means we still need to do it in this patch, right?

+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ChoiceConstraint.php
@@ -0,0 +1,38 @@
+   * Overrides Range::validatedBy().

{@inheritdoc}

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListBooleanItem.php
@@ -0,0 +1,115 @@
+ *   module = "options",

This wouldn't be needed anymore if we can get #2041423: Rely on 'provider' instead of 'module' for Field plugin types done before :(

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListBooleanItem.php
@@ -0,0 +1,115 @@
+  public static function schema(Field $field) {
+     return parent::schema($field) + array(
+       'columns' => array(
+         'value' => array(
+           'type' => 'int',
+           'not null' => FALSE,
+         ),
+       ),
+     );
+   }

There seems to be some weird indentation going on there and in all the other schema() implementations. This and the item below (accessing settings) needs to be fixed in all places :)

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListBooleanItem.php
@@ -0,0 +1,115 @@
+    $settings = $field['settings'];

You should use $field->getFieldSetting() instead of relying on the ArrayAccess implementation that should be removed soon.

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListItemBase.php
@@ -0,0 +1,273 @@
+ * Plugin base class used by the

by the... ?

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListItemBase.php
@@ -0,0 +1,273 @@
+   * @param $values
...
+   * @return

I know the code where this were copied from did not have them, but we should add type hints everywhere now.

+++ b/core/modules/options/options.module
@@ -382,7 +109,7 @@ function options_field_update_forbid($field, $prior_field) {
-    $field = field_info_field_by_id($field['uuid']);
+    $field = Field::fieldInfo()->getFieldById($field['uuid']);

Out of scope for this issue.

Thanks for working on this! :)

jsacksick’s picture

Thanks for your review amateescu, here's a new patch with some of the feedbacks addressed.

amateescu’s picture

Ohh, interdiff, nice :) You forgot the part that $settings = $field->getFieldSettings(); and type hints needs to be done for all new classes..

jsacksick’s picture

Is there any typehints left? Because I can't find them.

smiletrl’s picture

Good job!

+        'Choice' => array(
+          'choices' => array_keys($allowed_values),
+          'message' => t('%name: illegal value.', array('%name' => $instance['label'])),
+          'multiple' => $instance->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED,
+        ),

'multiple' will force validated value to be multiple values, i.e. an array. In this case, validator is validating FieldItem's each primitive 'value', an string or number. This line should be deleted to use the default 'multiple' value, i.e., false.

Also how about 'illegal value selected.':)

jsacksick’s picture

Yes but I'm only setting multiple to TRUE if the cardinality of the field is unlimited which is wrong, I should do that if the cardinality is != 1.

jsacksick’s picture

smiletrl’s picture

Hmm, cardinality != 1 will probably fail too:)

You may try an options field with cardinality != 1 and save the field.

jsacksick’s picture

Yes you're right, it seems we don't need the multiple flag there, it works fine without.

smiletrl’s picture

Maybe apply this change to demonstrate why 'multiple' line should be deleted:)

Status: Needs review » Needs work

The last submitted patch, Change_test_field_cardinality_to_2.patch, failed testing.

jsacksick’s picture

Status: Needs work » Needs review
amateescu’s picture

+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/ChoiceConstraint.php
@@ -0,0 +1,38 @@
+  /**
+   * Overrides Range::validatedBy().
+   */
+  public function validatedBy() {

index f9bbfa9..61004ef 100644
--- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/LengthConstraint.php

--- a/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/LengthConstraint.php
+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/LengthConstraint.php

+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/LengthConstraint.php
+++ b/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/LengthConstraint.php
@@ -31,7 +31,7 @@ class LengthConstraint extends Length {

@@ -31,7 +31,7 @@ class LengthConstraint extends Length {
   public $exactMessage = 'This value should have exactly %limit character.|This value should have exactly %limit characters.';
 
   /**
-   * Overrides Range::validatedBy().
+   * @inheritdoc
    */
   public function validatedBy() {

You updated the wrong class/method :) And it's {@inheritdoc}, notice the {}.

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListBooleanItem.php
@@ -0,0 +1,115 @@
+    $element += parent::settingsForm($form, $form_state, $element);

I think we should put the parent:: call at the top, as our class usually needs to add (or replace) something to the element provided by the parent.

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListFloatItem.php
@@ -0,0 +1,66 @@
+  public static function schema(Field $field) {
+     return parent::schema($field) + array(
+       'columns' => array(
+         'value' => array(
+           'type' => 'float',
+           'not null' => FALSE,
+         ),
+       ),
+     );
+   }

Wrong indentation here.

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListIntegerItem.php
@@ -0,0 +1,66 @@
+  public static function schema(Field $field) {
+     return parent::schema($field) + array(
+       'columns' => array(
+         'value' => array(
+           'type' => 'int',
+           'not null' => FALSE,
+         ),
+       ),
+     );
+   }

And here.

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListItemBase.php
@@ -0,0 +1,272 @@
+  public static function schema(Field $field) {
+     return array(
+       'indexes' => array(
+         'value' => array('value'),
+       ),
+     );
+   }

And here :P

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListTextItem.php
@@ -0,0 +1,85 @@
+  public static function schema(Field $field) {
+     return parent::schema($field) + array(
+       'columns' => array(
+         'value' => array(
+           'type' => 'varchar',
+           'length' => 255,
+           'not null' => FALSE,
+         ),
+       ),
+     );
+   }

...

No other complains otherwise :)

jsacksick’s picture

Thanks again for your review, I decided to remove the settingsForm implementation from the ListBooleanItem class and I regrouped everything in ListItemBase.

smiletrl’s picture

A quick review, this looks pretty good -- looks RTC to me:)

stevector’s picture

After applying this patch I got errors when trying to add list fields to a node bundle:

Fatal error: Declaration of Drupal\options\Plugin\field\field_type\ListItemBase::settingsForm() must be compatible with that of Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface::settingsForm() in /Users/persch/Sites/d8_dev/docroot/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListItemBase.php on line 16

and

Fatal error: Declaration of Drupal\options\Plugin\field\field_type\ListItemBase::schema() must be compatible with that of Drupal\field\Plugin\Type\FieldType\ConfigFieldItemInterface::schema() in /Users/persch/Sites/d8_dev/docroot/core/modules/options/lib/Drupal/options/Plugin/field/field_type/ListItemBase.php on line 16

Here's a reroll that should fix the errors.

yched’s picture

Status: Needs review » Postponed

#1758622: Provide the options list of an entity field is going to reformulate a couple things there, let's wait until it's in.

aspilicious’s picture

Status: Postponed » Needs work

Back to needs work as the linked issue is in :)

smiletrl’s picture

Status: Needs review » Needs work

Most stuff is associated with the validation. Some possible conversions:

1).
Options fieldItems should imlements interface AllowedValuesInterface
Personally speaking, I don't think it's really necessary for options module to implement this interface. Current options modules doesn't make use of hook_options_list. It provides allowed values via options_allowed_values

But the new OptionsWidgetBase has made use of this new interface, so it forces us to use this interface, if we are going to use this field widget. This also means we should probably move Options_allowed_values into that four methods of the new interface.

2).
Get rid of

+/**
+ * Choice constraint.
+ *
+ * Overrides the symfony constraint to use Drupal-style replacement patterns.
+ *
+ * @todo: Move this below the TypedData core component.
+ *
+ * @Plugin(
+ *   id = "Choice",
+ *   label = @Translation("Choice", context = "Validation"),
+ *   type = { "string" }
+ * )
+ */
+class ChoiceConstraint extends Choice {

We are going to make use this class AllowedValuesConstraint

3).

+  /**
+   * {@inheritdoc}
+   */
+  public function getConstraints() {
+    $constraint_manager = \Drupal::typedData()->getValidationConstraintManager();
+    $constraints = parent::getConstraints();
+    $instance = $this->getInstance();
+    $entity = $this->getParent()->getParent();
+
+    if (!isset($entity)) {
+      $ids = (object) array('entity_type' => $instance->entity_type, 'bundle' => $instance->bundle, 'entity_id' => NULL);
+      $entity = _field_create_entity_from_ids($ids);
+    }
+
+    $allowed_values = $this->flattenOptions(options_allowed_values($this->getInstance(), $entity));
+
+    $constraints[] = $constraint_manager->create('ComplexData', array(
+      'value' => array(
+        'Choice' => array(
+          'choices' => array_keys($allowed_values),
+          'message' => t('%name: illegal value selected.', array('%name' => $instance['label'])),
+        ),
+      ),
+    ));
+

This part could be updated. Change 'Choice' to 'AllowedValues'.
Add allowed values at getSettableValues(), see class AllowedValuesConstraintValidator
So, we also need to remove this line + 'choices' => array_keys($allowed_values),, becuase it will be overridden at the validator to make use of getSettableValues().

smiletrl’s picture

Status: Needs work » Needs review
FileSize
5.58 KB
40.07 KB

Most changes come from #39.

One Notable thing regarding TypedDataManager::getConstraints()

  // If the definition does not provide a class use the class from the type
  // definition for performing interface checks.
  $class = isset($definition['class']) ? $definition['class'] : $type_definition['class'];
  // Check if the class provides allowed values.
  if (array_key_exists('Drupal\Core\TypedData\AllowedValuesInterface', class_implements($class))) {
    $constraints[] = $validation_manager->create('AllowedValues', array());
  }

I think this part of code is wrong. This constraint added here will validate the whole object/typedData as value against an array of 'AllowedValues'. But in fact, we need to validate a property of the object, e.g., value of ListTextItem object here, to against an array of allowed values, not to validate the ListTextItem object itself against the allowed value array.

This part of code is deleted in this patch. Maybe a cleanup for #1758622: Provide the options list of an entity field, and it needs to add , or check existing test to show why this part of code should be deleted.

The last submitted patch, options_field_type-2015689-40.patch, failed testing.

smiletrl’s picture

Status: Needs work » Needs review
FileSize
1006 bytes
40.06 KB

There're still bugs, but post it here, in case someone else wants to play with it too.

Status: Needs review » Needs work

The last submitted patch, options_field_type-2015689-42.patch, failed testing.

smiletrl’s picture

Status: Needs work » Needs review
FileSize
5.71 KB
1.21 KB
40.19 KB

This time it should be fine.

interdiff-36-44.txt indicates the change since #36.

It includes a bug fix for #1758622: Provide the options list of an entity field.

-    if (array_key_exists('Drupal\Core\TypedData\AllowedValuesInterface', class_implements($class))) {
+    if (array_key_exists('Drupal\Core\TypedData\AllowedValuesInterface', class_implements($class)) && array_key_exists('Drupal\Core\TypedData\PrimitiveInterface', class_implements($class))) {
       $constraints[] = $validation_manager->create('AllowedValues', array());

The default constraints for object/class which implements AllowedValuesInterface isn't always as primitive value to validate against the allowed value array. If this object is an ComplexData, e.g., ListTextItem, then it will result in problem that tries to validate the whole object againt an array.

So, we need to make sure the default contraints at TypedDataManager::getConstraints only works for Prmitive value. The ComplexData's property constraints shoud be added at its own ::getConstraints function, like this:

+    $constraints[] = $constraint_manager->create('ComplexData', array(
+      'value' => array(
+        'AllowedValues' => array(
+          'message' => t('%name: illegal value selected.', array('%name' => $instance['label'])),
+        ),
+      ),
+    ));
smiletrl’s picture

oops:)

Status: Needs review » Needs work
Issue tags: -Field API

The last submitted patch, options_field_type-2015689-45.patch, failed testing.

smiletrl’s picture

Status: Needs work » Needs review
smiletrl’s picture

Issue tags: +Field API
smiletrl’s picture

smiletrl’s picture

Remove $this->getInstance() for fieldItem class.

smiletrl’s picture

Remove module entry.

swentel’s picture

swentel’s picture

Status: Needs review » Needs work

The last submitted patch, options_field_type-2015689-51.patch, failed testing.

smiletrl’s picture

Assigned: jsacksick » Unassigned

We als need to figure out the validation stuff in #2015687: Convert field type to FieldType plugin for taxonomy module .

catch’s picture

Priority: Normal » Critical

Marked #2014671: [META] Convert all field types to plugins as duplicate now we're down to the last two.

mradcliffe’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
39.9 KB

Attempt at a re-roll of the patch. Setting to needs review until test bot has a go at it (probably going to fail).

mradcliffe’s picture

Status: Needs review » Needs work
+++ b/core/modules/options/lib/Drupal/options/Plugin/Field/field_type/ListBooleanItem.php
@@ -0,0 +1,66 @@
+namespace Drupal\options\Plugin\field\field_type;

Namespace should be Drupal\options\Plugin\Field\FieldType

for all field types defined in this patch.

+++ b/core/modules/options/lib/Drupal/options/Plugin/Field/field_type/ListItemBase.php
@@ -0,0 +1,345 @@
+use Drupal\field\Plugin\Type\FieldType\ConfigFieldItemBase;

Class changed to

Drupal\Core\Field\ConfigFieldItemBase;

+++ b/core/modules/options/lib/Drupal/options/Plugin/Field/field_type/ListItemBase.php
@@ -0,0 +1,345 @@
+    if (in_array($field['type'], array('list_integer', 'list_float', 'list_text'))) {

$field is an object, not an array.

mradcliffe’s picture

Additionally there is a section in ListItemBase that requires the widget to change the allowed values description based on the widget. This is not possible in D8 because of form display modes.

mradcliffe’s picture

Status: Needs work » Needs review
FileSize
39.81 KB
67.92 KB

Here's a patch for review.

- I did not include the rename commit in the interdiff as it would make it as large as the patch itself.
- With regard to my previous comment, I made the description text contain all of the instructions. I have attached an image to show the output at a mobile width. More help text will make users' eyes glaze over and not read it. I think this is better than removing it altogether though.

mradcliffe’s picture

FileSize
5.5 KB

Forgot interdiff that I uploaded and then deleted twice in the previous comment due to slow ajax response.

Status: Needs review » Needs work

The last submitted patch, 61: interdiff-57-59.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 57: options_field_type-2015689-57.patch, failed testing.

mradcliffe’s picture

Status: Needs work » Needs review
FileSize
39.81 KB
1.31 KB

One line fix to fix all those test fails on my local install.

One line cosmetic fix.

star-szr’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Tagging for reroll.

mradcliffe’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
39.87 KB

Re-rolled.

- fetched origin
- rebase origin/8.x
- diff origin/8.x

Edit: I hid some older patches.

Status: Needs review » Needs work

The last submitted patch, 66: 2015689-drupal-options-field-type-66.patch, failed testing.

mradcliffe’s picture

Status: Needs work » Needs review
FileSize
40.9 KB
3.6 KB

Changes form_error() usage to \Drupal::formBuilder()->setError() with additional $form_state parameter.

catch’s picture

Issue tags: +beta blocker
mradcliffe’s picture

The last submitted patch, 68: 2015689-drupal-options-field-type-68.patch, failed testing.

mradcliffe’s picture

Simple re-roll with git rebase origin/8.x

Status: Needs review » Needs work

The last submitted patch, 72: 2015689-drupal-options-field-type-72.patch, failed testing.

mradcliffe’s picture

Status: Needs work » Needs review
FileSize
41.02 KB
5.07 KB

The last submitted patch, 74: 2015689-drupal-options-field-type-74.patch, failed testing.

jibran’s picture

Status: Needs review » Needs work

Patch failed.

mradcliffe’s picture

Status: Needs work » Needs review
FileSize
41.01 KB
1.66 KB

The last submitted patch, 77: 2015689-drupal-options-field-type-77.patch, failed testing.

fago’s picture

+++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php
@@ -362,7 +362,7 @@ public function getConstraints(DataDefinitionInterface $definition) {
-    if (is_subclass_of($class,'Drupal\Core\TypedData\AllowedValuesInterface')) {
+    if (is_subclass_of($class,'Drupal\Core\TypedData\AllowedValuesInterface') && is_subclass_of($class, 'Drupal\Core\TypedData\PrimitiveInterface')) {
       $constraints[] = $validation_manager->create('AllowedValues', array());

Instead of removing it, this should embrace allowed values validation now - analogously to term references.

smiletrl’s picture

@mradcliffe thanks for your work!

Here's a patch to clean the code a bit. Also, the main property of list field is 'value', so the default main property of FieldItemBase should be ok to do with AllowedValuesInterface.

mradcliffe’s picture

Just to clarify, will the flattenOptions method on formBuilder make a tighter dependency on field validation/constraints and the Form API? I'm not familiar with the new \Drupal static methods and how loose or tight they are.

smiletrl’s picture

\Drupal::formBuilder() is a core required method, i.e. form api is a required component. So, from my eyes, the dependency could be ignored and it's ok to use these methods in other parts, not just inside form api.

There're many other methods created by \Drupal container, and we have used them everywhere, e.g., \Drupal::typedDataManager().

mradcliffe’s picture

Yes, I know we like to depend on the container a lot already. I think it's probably the easiest way to get the patch in. Being able to solve this issue would be best in Drupal 9. It's always good to start thinking about it now. For instance, field validation is not necessarily form validation.

Berdir’s picture

Assigned: Unassigned » fago

I think this needs to be reviewed by @fago, I'm not up to date enough with the allowed values discussion that happened in the taxonomy issue to RTBC this.

Berdir’s picture

The last submitted patch, 80: drupal_options_field_type-2015689-80.patch, failed testing.

smiletrl’s picture

This should fix that problem.

effulgentsia’s picture

The last submitted patch, 87: drupal_options_field_type-2015689-87.patch, failed testing.

effulgentsia’s picture

effulgentsia’s picture

This is just a code cleanup with no intended functional changes.

effulgentsia’s picture

The last submitted patch, 91: drupal_options_field_type-2015689-91.patch, failed testing.

effulgentsia’s picture

+++ b/core/modules/options/options.module
@@ -25,184 +25,6 @@ function options_help($path, $arg) {
-  // Alter the description for allowed values depending on the widget type.
-  if ($field_type == 'list_boolean') {
-    $form['allowed_values']['#description'] .= '<p>' . t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") . '</p>';
-  }
+++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php
@@ -0,0 +1,306 @@
+    // It is no longer possible to alter the description of allowed values
+    // depending on widget type because of form displays. The help text must
+    // instead be verbose.
+    $element['allowed_values']['#description'] .= '<p>' . t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") . '</p>';
+    $element['allowed_values']['#description'] .= '<p>' . t("The 'checkboxes/radio buttons' widget will display checkboxes if the <em>Number of values</em> option is greater than 1 for this field, otherwise radios will be displayed.") . '</p>';

This UI change seems out of scope for this issue, so this patch reverts it, but attempts to improve the code comment that I think caused the confusion that led to the initial change.

I reviewed #87 quite thoroughly prior to my round of minor tweaks, and from my perspective, this patch is now good to go, including the way that AllowedValuesInterface is used (per #84). But since this is assigned to fago, and I've now authored some of it, I'll defer to him to RTBC. I agree with #83 that some of the dependencies on services in Drupal:: can be improved but that none of that is a regression from HEAD or release blocking. Anyone who wants to can still work on improving that in a follow up.

The last submitted patch, 92: drupal_options_field_type-2015689-92.patch, failed testing.

The last submitted patch, 94: drupal_options_field_type-2015689-93.patch, failed testing.

smiletrl’s picture

This should fix the problem.

The last submitted patch, 97: drupal_options_field_type-2015689-97.patch, failed testing.

effulgentsia’s picture

fago’s picture

Assigned: fago » Unassigned
Status: Needs review » Needs work

I agree with #83 that some of the dependencies on services in Drupal:: can be improved but that none of that is a regression from HEAD or release blocking.

Definitely!

Patch looks pretty good to me. I just found some small issues (see below), else this looks RTBC to me.

  1. +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php
    @@ -0,0 +1,308 @@
    + * Plugin base class inherited by the options field types.
    ...
    +    // Flatten options firstly, because Settable Options may contain group
    ...
    +   *   Boolean value indicating whether to generate keys based on the position of
    

    Comment exceeds 80chars.

  2. +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php
    @@ -0,0 +1,308 @@
    +   * @see options_allowed_values_string()
    

    This needs to be updated to point to the method.

  3. +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php
    @@ -0,0 +1,82 @@
    +          'max' => 255,
    ...
    +    $constraints[] = $constraint_manager->create('ComplexData', array(
    +      'value' => array(
    

    This should be in the data definition of the 'value' property as there is no reason to define it dynamically here.

yched’s picture

No other remarks than @fago's #100.

Not strictly related, but while reviewing, created the following issues:
#2171393: Remove implementation of removed hook_options_list()
#2171395: OptionsWidgetBase should use WidgetInterface::massageFormValues()

smiletrl’s picture

Status: Needs work » Needs review
FileSize
40.09 KB
2.75 KB

Indeed, constraints should be moved.

Berdir’s picture

  1. +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php
    @@ -228,16 +228,17 @@ public function validateAllowedValues($element, &$form_state) {
        *   The list of allowed values in string format described in
    -   *   options_allowed_values_string().
    +   *   allowedValuesString().
    

    This needs to be ListItemBase::allowedValuesString(), otherwise it's a function.

  2. +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php
    @@ -55,28 +55,11 @@ public static function schema(FieldDefinitionInterface $field_definition) {
       public function getPropertyDefinitions() {
         if (!isset(static::$propertyDefinitions)) {
    +      $constraints = array('Length' => array('max' => 255));
           static::$propertyDefinitions['value'] = DataDefinition::create('string')
    -        ->setLabel(t('Text value'));
    +        ->setLabel(t('Text value'))
    +        ->setConstraints($constraints);
        }
    

    This seems short enough to put it on a single line, but fine if we do it like this elsewhere too.

smiletrl’s picture

oops, missed that~

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Changes look good, @fago, @effulentsia and @yched confirmed everything else, that should be enough. RTBC :)

yched’s picture

Sorry, I thought I posted that, but apparently closed the tab before doing so :-/

+++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php
@@ -238,7 +238,7 @@ public function validateAllowedValues($element, &$form_state) {
+   * @see ListItemBase::allowedValuesString()

I think @see needs to have the full namespaced class so that it gets correclty parsed by api.module

(just reacting to the last interdiff, didn't check the rest of the patch for other ocurrences)

smiletrl’s picture

Thanks, fixed. No other occurences.

yched’s picture

Thanks @smilerl. RTBC+1.

webchick’s picture

Title: Convert field type to typed data plugin for options module » Change notice: Convert field type to typed data plugin for options module
Priority: Critical » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Great work folks!

Committed and pushed to 8.x.

I believe this now un-postpones #2087393: Remove LegacyField once all field types converted.

We may need to add to/extend an existing change notice about this, so tagging.

xjm’s picture

Issue tags: +Missing change record

Tagging "Missing change record", as completing the change record updates here blocks a beta: #2083415: [META] Write up all outstanding change notices before release

Berdir’s picture

Title: Change notice: Convert field type to typed data plugin for options module » Convert field type to typed data plugin for options module
Status: Active » Fixed
Issue tags: -Needs change record, -Missing change record

I think we're good, this is part of the meta that is already referenced in https://drupal.org/node/2064123 and this was simply the last one to be converted.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.