You are here

public function EntityIsOfBundle::assertMetadata in Rules 8.3

Asserts additional metadata for the selected data.

Allows the plugin to assert additional metadata that is in place when the plugin has been successfully executed. A typical use-case would be asserting the node type for a "Node is of type" condition. By doing so, sub-sequent executed plugins are aware of the metadata and can build upon it.

Implement this method, when the selected data definitions need to be refined. When the plugin's context definitions should be refined, implement ::refineContextDefinitions() instead.

Note that metadata is only asserted on configuration time. The plugin has to ensure that the run-time data matches the asserted configuration if it has been executed successfully.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface[] $selected_data: An array of data definitions for context that is mapped using a data selector, keyed by context name.

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An array of modified data definitions, keyed as the passed array. Note data definitions need to be cloned *before* they are modified, such that the changes do not propagate unintentionally.

Overrides RulesConditionBase::assertMetadata

File

src/Plugin/Condition/EntityIsOfBundle.php, line 63

Class

EntityIsOfBundle
Provides an 'Entity is of bundle' condition.

Namespace

Drupal\rules\Plugin\Condition

Code

public function assertMetadata(array $selected_data) {

  // Assert the checked bundle.
  $changed_definitions = [];
  if (isset($selected_data['entity']) && ($bundle = $this
    ->getContextValue('bundle'))) {
    $changed_definitions['entity'] = clone $selected_data['entity'];
    $bundles = is_array($bundle) ? $bundle : [
      $bundle,
    ];
    $changed_definitions['entity']
      ->setBundles($bundles);
  }
  return $changed_definitions;
}