Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grimreaper created an issue. See original summary.

Piegefull’s picture

Give the option to select the condition plugins in the field settings.

Piegefull’s picture

Assigned: Piegefull » Grimreaper
Status: Active » Needs review
Grimreaper’s picture

Assigned: Grimreaper » Piegefull
Status: Needs review » Needs work
  1. +++ b/entity_visibility_preview.module
    @@ -39,7 +36,9 @@ function entity_visibility_preview_entity_access(EntityInterface $entity, $opera
    +        if ($field->isFeatureEnabled($condition_plugin_id)) {
    

    Error: Call to undefined method Drupal\Core\Field\FieldItemList::isFeatureEnabled() in entity_visibility_preview_entity_access() (line 42 of modules/contrib/entity_visibility_preview/entity_visibility_preview.module).

    $field is a FieldItemList and not a entity_visibility_preview/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php.

    You can access field settings using $field_definition->settings["enabled_condition_plugins"]["date_range_condition"].

    Also it is better to check if the plugin is enabled before instanciating it.

  2. +++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
    @@ -41,6 +42,57 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
    +    ] + parent::defaultStorageSettings();
    

    parent::defaultFieldSettings()

  3. +++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
    @@ -41,6 +42,57 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
    +      '#multiple' => TRUE,
    

    This key is for select, table, tableselect and file.

  4. +++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
    @@ -41,6 +42,57 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
    +   * @return array|null
    

    array only.

  5. +++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
    @@ -41,6 +42,57 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
    +        $entityVisibilityPreviewConditionPluginManager = \Drupal::service('plugin.manager.entity_visibility_preview_condition');
    

    Dependency injection.

  6. +++ b/src/Plugin/Field/FieldWidget/EntityVisibilityPreviewWidget.php
    @@ -90,6 +94,11 @@ class EntityVisibilityPreviewWidget extends WidgetBase implements ContainerFacto
    +    // If the field hasn't a plugin selected, remove the form.
    

    If the field has no plugin selected, hide the form.

  7. +++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
    @@ -74,4 +126,21 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
    +   *   Feature name to check.
    

    Condition plugin ID to check.

  8. +++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
    @@ -74,4 +126,21 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
    +  public function isFeatureEnabled($condition_plugin) {
    

    Better to put this method into the plugin manager.

    Parameter one will be the list of enabled/disabled plugin.

    Or also you can create a method in the plugin manager, getEnabledDefinitions() with this parameter, so instead of having loops on all the plugins and then checking if the plugin needs to be instanciated, you can loop on plugins you now they are enabled.

  9. +++ b/src/Plugin/Field/FieldWidget/EntityVisibilityPreviewWidget.php
    @@ -71,17 +71,21 @@ class EntityVisibilityPreviewWidget extends WidgetBase implements ContainerFacto
    +      if ($item->isFeatureEnabled($plugin_id)) {
    

    At the beginning of the method.

    /** @var \Drupal\entity_visibility_preview\Plugin\Field\FieldType\EntityVisibilityPreviewItem $item */

    So $item is typed and the IDE verification is happy.

Piegefull’s picture

Version: » 8.x-1.x-dev
Assigned: Piegefull » Grimreaper
Status: Needs work » Needs review
FileSize
25.75 KB
Piegefull’s picture

Grimreaper’s picture

Assigned: Grimreaper » Piegefull
Status: Needs review » Needs work
  1. ok
  2. ok
  3. ok
  4. ok
  5. seen together, can't find quickly an example in core to see how it is done.
  6. not done
  7. no more relevant as the method had been moved into the plugin manager
  8. ok
  9. ok
Piegefull’s picture

  • Piegefull authored 9c3b63b on 8.x-1.x
    Issue #3096816 by Piegefull, Grimreaper: Be able to enable each plugin...
Grimreaper’s picture

Assigned: Piegefull » Unassigned
Status: Needs work » Fixed

Merged!

If there is still other small picks, we will see the in a whole review after.

Status: Fixed » Closed (fixed)

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