Comments

fago’s picture

Status: Postponed » Active
netsensei’s picture

Maybe i'm underestimating the amount of work here, but willing to take a look at this anyway, if that's ok.

netsensei’s picture

Assigned: Unassigned » netsensei
yched’s picture

Thanks @netsensei ! Should be fairly simple ;-)

netsensei’s picture

Status: Active » Needs review
StatusFileSize
new2.66 KB
yched’s picture

+++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php
@@ -81,4 +88,37 @@ public function getDefaultInstanceSettings($type) {
+      $field_types = $this->getDefinitions();
+      // Gather valid field types.
+      foreach ($field_types as $name => $field_type) {

Nitpick: I'd just shorten that to foreach ($this->getDefinitions() as $field_type => $definition) {

Other than that, looks ready to me :-)

netsensei’s picture

StatusFileSize
new1019 bytes
new2.64 KB

Great. :-) Adapted the patch.

yched’s picture

Status: Needs review » Reviewed & tested by the community

Works for me. Thanks !

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we need to override clearCachedDefinitions() to clear fieldTypeOptions property and call the parent.

netsensei’s picture

Status: Needs work » Needs review
StatusFileSize
new877 bytes
new2.81 KB

Added the override of clearCachedDefinitions(). Clears fieldTypeOptions property.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2017711-FieldTypePluginManager-getOptions-10.patch, failed testing.

swentel’s picture

Status: Needs work » Reviewed & tested by the community

@Alex, why would we want to do that ? We don't do it either in the widget or formatter plugin manager, and it's not that the list of field types is going to change during the request or so. It can (and honestly only /may/) change when enabling or disabling a module.

Moving back to RTBC for #7 and to get feedback since I couldn't get you on IRC :)

webchick’s picture

Assigned: netsensei » alexpott

I am not sure. :) Assigning to Alex. He's currently on vacation but I believe gets back next week.

xano’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2017711-FieldTypePluginManager-getOptions-10.patch, failed testing.

plopesc’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new3.07 KB

Re-rolling patch in #7 and adding getOptions() to FieldTypePluginManagerInterface in order to improve type hinting.

Status: Needs review » Needs work

The last submitted patch, 17: fieldtypepluginmanager_options-2017711-17.patch, failed testing.

plopesc’s picture

Status: Needs work » Needs review
StatusFileSize
new3.12 KB
new2.09 KB

Ups, I didn't realize that getDefinitions() had to be renamed to getConfigurableDefinitions().
Using this method, and renaming getOptions() to getConfigurableOptions() to keep consistency.
Sorry for the noise.

berdir’s picture

swentel’s picture

Status: Needs review » Needs work

The last submitted patch, 19: fieldtypepluginmanager_options-2017711-19.patch, failed testing.

jsbalsera’s picture

Rerolled

jsbalsera’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: fieldtypepluginmanager_options-2017711-23.patch, failed testing.

jsbalsera’s picture

So the reroll wasn't as simple as expected, working on the failing tests

jsbalsera’s picture

Status: Needs work » Needs review
StatusFileSize
new3.21 KB

Changing getConfigurable* for getUi* when it's needed

jsbalsera’s picture

StatusFileSize
new2.08 KB

Forgot the interdiff, sorry

berdir’s picture

  1. +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php
    @@ -81,4 +96,28 @@ public function getUiDefinitions() {
    +  public function getUiOptions($type = NULL) {
    

    Not sure if this method name makes sense, there are only ui options, so maybe just getOptions() would be enough? Not sure.. maybe discuss with someone else, swentel?

  2. +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php
    @@ -81,4 +96,28 @@ public function getUiDefinitions() {
    +      foreach ($this->getUiDefinitions() as $field_type => $definition) {
    +        // Skip field types which should not be added via user interface.
    +        if (empty($definition['no_ui'])) {
    +          $options[$field_type] = $definition['label'];
    +        }
    +      }
    

    THe check is no longer necessary, because getUiDefinitions() already filters no_ui out.

swentel’s picture

Yeah, getOptions() is better and consistent with the formatter and widget manager.

jsbalsera’s picture

Assigned: alexpott » jsbalsera
StatusFileSize
new3.08 KB
new2.1 KB

Changing name and fixing 2.

jsbalsera’s picture

Assigned: jsbalsera » Unassigned
berdir’s picture

  1. +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php
    @@ -19,6 +19,21 @@
       /**
    +   * {@inheritdoc}
    +   */
    +  protected $defaults = array(
    +    'settings' => array(),
    +    'instance_settings' => array(),
    +  );
    

    I think this is a merge conflict and shouldn't be here

  2. +++ b/core/lib/Drupal/Core/Field/FieldTypePluginManagerInterface.php
    @@ -46,4 +46,17 @@ public function getDefaultSettings($type);
    +   *
    +   * @param string|null $field_type
    +   *   (optional) The name of a field type, or NULL to retrieve all field
    +   *   options. Defaults to NULL.
    +   *
    +   * @return array
    +   *   If no field type is provided, returns a nested array of all field labels,
    +   *   keyed by field type machine name.
    

    There's no $field_name param, I think that's incorrectly copied from widget/formatter methods?

    So remove @param and simplify @return.

    Maybe explicitly specify somewhere in the description that this will only return fields that can be added in the UI and have a default widget and formatter? Possibly as a second line after the initial sentence?

jsbalsera’s picture

StatusFileSize
new2.85 KB
new1.54 KB

Fixing 1. and change docblock as described in 2.

alansaviolobo’s picture

StatusFileSize
new2.01 KB

reroll

xano’s picture

Status: Needs review » Needs work

I'm not sure we should be adding UI helpers to an API-level class like a plugin manager. Can we move this to a separate class so we separate responsibilities?

+++ b/core/lib/Drupal/Core/Field/FieldTypePluginManager.php
@@ -163,4 +170,25 @@ public function getPluginClass($type) {
+  public function getOptions($type = NULL) {

I know this has been done all over core, but we should stop adding such switch parameters to methods, and instead create separate methods so return values' structures are actually predictable and easy to document.

jcnventura’s picture

Xano, valid points, but this should be done with the same pattern as the the Widget and Formatter plugins.

As it's too late to remove getOptions from the others, I think that it's more coherent this way.

jcnventura’s picture

Status: Needs work » Needs review

Testbots are go!

xano’s picture

I still disagree. It provides inconsistent DX. It's a new method on an interface (which is also a BC break), so it's a chance to do it right.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

Wonder after 7 years if this is still a valid task?

If so it will need to be updated for D10 and I believe it will need tests.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

If still a valid task please reopen but closing for now.

amateescu’s picture

Just wanted to point out that this issue really is outdated, all the code around adding fields from the UI was shuffled a lot in #3356894: Make field selection less overwhelming by introducing groups and the followup issues.