getBundleInfo($content_entity); foreach ($bundles as $bundle => $bundle_properties) { $options[$bundle] = $this->t('@bundle (@type)', [ '@bundle' => $bundle_properties['label'], '@type' => $content_entity, ]); } } $form['bundles'] = [ '#title' => $this->t('Bundles'), '#type' => 'checkboxes', '#options' => $options, '#default_value' => $this->configuration['bundles'], ]; return parent::buildConfigurationForm($form, $form_state);; } /** * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { $this->configuration['bundles'] = array_filter($form_state->getValue('bundles')); parent::submitConfigurationForm($form, $form_state); } /** * {@inheritdoc} */ public function evaluate() { foreach ($this->getContexts() as $context) { if ($context->hasContextValue()) { $entity = $context->getContextValue(); if (!empty($this->configuration['bundles'][$entity->bundle()])) { return TRUE; } } } return FALSE; } /** * {@inheritdoc} */ public function summary() { if (empty($this->configuration['bundles'])) { return $this->t('No bundles are selected.'); } return $this->t( 'Entity bundle in the list: @bundles', [ '@bundles' => implode(', ', $this->configuration['field']), ] ); } /** * {@inheritdoc} */ public function defaultConfiguration() { return array_merge( ['bundles' => []], parent::defaultConfiguration() ); } }