Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
+++ 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.
+++ 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.
+++ b/src/Plugin/Field/FieldType/EntityVisibilityPreviewItem.php
@@ -74,4 +126,21 @@ class EntityVisibilityPreviewItem extends FieldItemBase {
+ * Feature name to check.
Condition plugin ID to check.
+++ 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.
+++ b/src/Plugin/Field/FieldWidget/EntityVisibilityPreviewWidget.php
@@ -71,17 +71,21 @@ class EntityVisibilityPreviewWidget extends WidgetBase implements ContainerFacto
+ if ($item->isFeatureEnabled($plugin_id)) {
Comments
Comment #2
Piegefull CreditAttribution: Piegefull at Smile commentedGive the option to select the condition plugins in the field settings.
Comment #3
Piegefull CreditAttribution: Piegefull at Smile commentedComment #4
GrimreaperError: 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.
parent::defaultFieldSettings()
This key is for select, table, tableselect and file.
array only.
Dependency injection.
If the field has no plugin selected, hide the form.
Condition plugin ID to check.
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.
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.
Comment #5
Piegefull CreditAttribution: Piegefull at Smile commentedComment #6
Piegefull CreditAttribution: Piegefull at Smile commentedComment #7
GrimreaperComment #8
Piegefull CreditAttribution: Piegefull at Smile commentedComment #9
Piegefull CreditAttribution: Piegefull at Smile commentedComment #11
GrimreaperMerged!
If there is still other small picks, we will see the in a whole review after.