This is one of the sub-tasks of #1742734: [META] Widgets as Plugins to convert all core widgets. This is currently explicitly postponed.

CommentFileSizeAuthor
#58 options_widgets_plugins-1751234-58.patch30.68 KByched
#58 interdiff.txt3.41 KByched
#55 options_widgets_plugins-1751234-55.patch30.06 KByched
#53 Screen Shot 2013-04-15 at 21.41.22.png31.74 KBswentel
#53 options_widgets_plugins-1751234-53.patch31.3 KBswentel
#53 interdiff.txt233 bytesswentel
#52 options_widgets_plugins-1751234-52.patch31.33 KByched
#52 interdiff.txt1.11 KByched
#50 options_widgets_plugins-1751234-50.patch30.09 KByched
#50 interdiff.txt560 bytesyched
#48 options_widgets_plugins-1751234-48.patch30.07 KByched
#45 options_widgets_plugins-1751234-45.patch30.7 KByched
#42 options_widgets_plugins-1751234-42.patch30.47 KByched
#40 options_widgets_plugins-1751234-40.patch30.39 KBamateescu
#40 interdiff.txt595 bytesamateescu
#38 options_widgets_plugins-1751234-38.patch30.45 KBamateescu
#38 interdiff.txt1.05 KBamateescu
#32 options_widgets_plugins-1751234-32.patch30.45 KBamateescu
#32 interdiff.txt3.05 KBamateescu
#25 options_widgets_plugins-1751234-25.patch30.49 KBswentel
#25 interdiff.txt1.04 KBswentel
#24 options_widgets_plugins-1751234-24.patch30.48 KByched
#22 options_widgets_plugins-1751234-22.patch31.09 KByched
#21 options_widgets_plugins-1751234-21.patch31.09 KByched
#16 1751234-16_options_widgets_plugins.patch30.27 KBpcambra
#13 1751234-13_options_widgets_plugins.patch30.7 KBwebflo
#10 1751234-9_options_widgets_plugins.patch33.15 KBkotnik
#7 options_widgets_plugins-1751234-7.patch31.91 KByched
#5 options_widgets_plugins-1751234-5.patch30.05 KByched
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Note : the porting is basically done already in a sandbox of mine.
Don't start this without pinging me.

pcambra’s picture

Title: Implement the options_buttons widget as a Plugin » Convert option module widgets to Plugin system

These are the current widgets:

  • options_select
  • options_buttons
  • options_onoff
swentel’s picture

yched’s picture

Yup, that's because taxonomy module currently relies on hoo_field_widget_info_alter() to use option widgets (select / checkboxes) on taxo terms.
But without #1705702: Provide a way to allow modules alter plugin definitions, the hook runs only within HookDiscovery, and thus cannot affect widgets exposed in annotations. So, this works while option widgets stay in the old API.

yched’s picture

Title: Convert option module widgets to Plugin system » Convert option widgets to Plugin system
Project: D8 Field API » Drupal core
Version: » 8.x-dev
Component: Code » field system
Status: Postponed » Needs review
FileSize
30.05 KB

Extracted and adapted the code from my old sandbox.

Also, added a workaround in LegacyDiscoveryDecorator to allow taxonomy fields to use option widgets - meaning #1705702: Provide a way to allow modules alter plugin definitions is not a blocker anymore.

(note : code lives in a new field-plugins-widgets-options-1751234 branch in the D8 Field API sandbox)

Status: Needs review » Needs work

The last submitted patch, options_widgets_plugins-1751234-5.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
31.91 KB

Fixed tests - the UI for "on/off checkbox" does not allow '0' as a 'on' value anymore, so the widget code does not support it either, but that was still the case being tested.

kotnik’s picture

Status: Needs review » Needs work
yched’s picture

@kotnik: right, but it was actually not a blocker anymore :-)

kotnik’s picture

Rebased so it can be applied.

Also, hook_field_widget_info_alter() is never called, so taxonomy module fields have only autocomplete option. I think we should fix it here, just not sure how.

yched’s picture

Status: Needs work » Needs review

Also, hook_field_widget_info_alter() is never called, so taxonomy module fields have only autocomplete option

Yes, see #1785256-46: Widgets as Plugins. Should be fixed in a separate patch over there.

kotnik’s picture

Yes, see #1785256-46: Widgets as Plugins. Should be fixed in a separate patch over there.

It's actually fixed in #1817180: Tests: hook_widget_info_alter() is not called anymore.

webflo’s picture

nils.destoop’s picture

Looks good. But i see taxonomy_field_widget_info_alter from #1751244: Convert taxonomy module widgets to Plugin system is also in this patch.

Small docs remark in OptionsButtonsWidget. It still says: Plugin implementation of the 'options_select' widget.

nils.destoop’s picture

Also an extra remark. Maybe we should recheck the widget class names.

OptionsOnOffWidget can be OnOffWidget, or even CheckboxWidget. OptionsSelectWidget can be SelectWidget. OptionsButtonsWidget can be ButtonsWidget.

pcambra’s picture

Fixed #14, let's not mix patches.

I'm not sure it we should rename the widgets themselves as text and number are using this naming pattern (Module+Scope+Widget), what I renamed is the "Base" thing out of the option widget as we're not using base for anything else (number or text)

Status: Needs review » Needs work

The last submitted patch, 1751234-16_options_widgets_plugins.patch, failed testing.

webflo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1751234-16_options_widgets_plugins.patch, failed testing.

nils.destoop’s picture

Status: Needs work » Needs review
yched’s picture

Actually, agreed with zuuperman that the 'Options' prefix is useless. But the base class is an abstract base class, not an actual widget implementation, so It should have 'Base' as a suffix.

- Renamed classed to SelectWidget, ButtonsWidget, OnOffWidget and (back to) OptionsWidgetBase
- Adjusted phpdocs to the recent code conventions
- Moved options_field_widget_validate() (#element_validate callback) to a method in OptionsWidgetBase, now that it's possible. Done as a static method, so that $this (the widget object, including the $field and $instance structs) does not get serialized with the form.

No easy interdiff, due to the file renames, sorry.

yched’s picture

Reroll + bump ?

yched’s picture

yched’s picture

Hmm, looks like I forgot to actually upload the patch last time :-/.

Anyway. Reroll after entity_reference.
& bump :-)

swentel’s picture

We need this for #1875992: Add EntityFormDisplay objects for entity forms - new patch with two minor changes - should be still green, so will RTBC when it comes back green.

Status: Needs review » Needs work

The last submitted patch, options_widgets_plugins-1751234-25.patch, failed testing.

amateescu’s picture

Afaik, these are the last remaining uses of the LegacyWidget plugin, shouldn't we remove it in this patch?

swentel’s picture

Hmm good idea, I'll look at it this evening (unless someone beats me to it).

swentel’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, options_widgets_plugins-1751234-25.patch, failed testing.

swentel’s picture

Note, we don't have to kill this off yet, #1796316: Convert Link/URL widgets / formatters to plugin system is still open

amateescu’s picture

Status: Needs work » Needs review
FileSize
3.05 KB
30.45 KB

This one should be better.

yched’s picture

Thanks for unbreaking this folks :-)

-    $info['options_select']['field_types'][] = 'taxonomy_term_reference';
+    $info['options_select']['field_types'][] = 'entity_reference';

So soon ? 'taxonomy_term_reference' field type still exists for now, right ?

amateescu’s picture

Look where that change was made ;)

yched’s picture

Er, doh, right...

amateescu’s picture

You thought I was going mad from that taxonomy field deprecation issue, right? Well.. not yet! :P

Status: Needs review » Needs work

The last submitted patch, options_widgets_plugins-1751234-32.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
FileSize
1.05 KB
30.45 KB

Argh..

yched’s picture

Ah, right. Which means there probably is a "use DiscoveryInterface" statement that can be dropped in OptionsWidgetBase...

amateescu’s picture

That's right :)

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me.

yched’s picture

Rerolled after #1801356: Entity reference autocomplete using routes, entity_reference_menu() is gone - unrelated, but just broke hunk context.

xjm’s picture

swentel’s picture

Status: Reviewed & tested by the community » Postponed

We're going to postpone on #1735118: Convert Field API to CMI, that one is close, bear with us folks!

yched’s picture

Status: Postponed » Reviewed & tested by the community
FileSize
30.7 KB
swentel’s picture

Live from the party, we need to check for the 'inheritdoc' comments - see comment on field API patch. Also applies to the other patches.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, options_widgets_plugins-1751234-45.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
30.07 KB

--> {@inheritdoc}

Status: Needs review » Needs work

The last submitted patch, options_widgets_plugins-1751234-48.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
560 bytes
30.09 KB

Damn, how did I miss that one ?

Status: Needs review » Needs work

The last submitted patch, options_widgets_plugins-1751234-50.patch, failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
1.11 KB
31.33 KB

Reroll, but the test fails are beyond me.

- Can't reproduce the "Cannot modify header information" warning in Drupal\system\Tests\Common\AddFeedTest
- *Can* reproduce the fail in Drupal\taxonomy\Tests\TermTest, happens on those lines :

  $json = $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input)));
  $this->assertEqual($json, '{"\u0022' . $term_objects['term3']->name . '\u0022":"' . $term_objects['term3']->name . '"}'

The assertEqual fails because with patch, the $json string starts by a carriage return, which is not the case in HEAD.
I have absolutely no clue why the patch would have such an effect, though.

For now, made the test pass again by adding a trim($json), but something is weird here.

swentel’s picture

I think they both failed thanks to a nice newline in options module ;)

Screen Shot 2013-04-15 at 21.41.22.png

yched’s picture

LOL. Headdesk time. There goes one hour of my life.
Thanks @swentel :-)

yched’s picture

Reverting the trim() change in Drupal\taxonomy\Tests\TermTest, then (was interdiff #52)

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Ok, let's do this.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/ButtonsWidget.phpundefined
@@ -0,0 +1,76 @@
+  protected function getEmptyOption() {
+    if (!$this->required && !$this->multiple) {
+      return self::OPTIONS_EMPTY_NONE;
+    }
+  }

We should be using late static binding so "if you subclass, you should be able to override the constant" (@timplunkett)

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.phpundefined
@@ -0,0 +1,206 @@
+  /**
+   * Returns the empty option to add to the list of options, if any.
+   *
+   * @return string|null
+   *   Either self::OPTIONS_EMPTY_NONE, self::OPTIONS_EMPTY_SELECT, or NULL.
+   */

We should be using late static binding...

+++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/SelectWidget.phpundefined
@@ -0,0 +1,85 @@
+  protected function getEmptyOption() {
+    if ($this->multiple) {
+      // Multiple select: add a 'none' option for non-required fields.
+      if (!$this->required) {
+        return self::OPTIONS_EMPTY_NONE;
+      }
+    }
+    else {
+      // Single select: add a 'none' option for non-required fields,
+      // and a 'select a value' option for required fields that do not come
+      // with a value selected.
+      if (!$this->required) {
+        return self::OPTIONS_EMPTY_NONE;
+      }
+      if (!$this->has_value) {
+        return self::OPTIONS_EMPTY_SELECT;
+      }
+    }
+  }

We should be using late static binding...

Also in the complete theme_options_none function now looks like:

/**
 * Returns HTML for the label for the empty value for non-required options.
 *
 * The default theme will display 'N/A' for a radio list and '- None -' or
 * 'Select a value' for a select.
 *
 * @param $variables
 *   An associative array containing:
 *   - option: A string representing the option that should be displayed.
 *     Either 'option_none' or 'option_select'.
 *   - widget: The widget object requesting the option.
 *   - instance: The instance definition.
 *
 * @ingroup themeable
 */
function theme_options_none($variables) {
  $option = $variables['option'];
  $widget = $variables['widget'];

  $output = '';
  switch ($widget->getPluginId()) {
    case 'options_buttons':
      $output = t('N/A');
      break;

    case 'options_select':
      $output = ($option == 'option_none' ? t('- None -') : t('- Select a value -'));
      break;
  }

  return $output;
}

$output = ($option == 'option_none' ? t('- None -') : t('- Select a value -')); should use the constant from the class...

use Drupal\options\Plugin\field\widget\OptionsWidgetBase;
$output = ($option == OptionsWidgetBase::OPTIONS_EMPTY_NONE ? t('- None -') : t('- Select a value -'));

And then the function docblock needs to be updated to say...

 *   - option: A string representing the option that should be displayed.
 *     Either OptionsWidgetBase::OPTIONS_EMPTY_NONE or OptionsWidgetBase::OPTIONS_EMPTY_SELECT.
yched’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
3.41 KB
30.68 KB

Right, fixed.

yched’s picture

Priority: Normal » Major
alexpott’s picture

Committed 6fa5b69 and pushed to 8.x. Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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