You are here

public function DataSet::autoSaveContext in Rules 8.3

Returns a list of context names that should be auto-saved after execution.

Return value

array A subset of context names as specified in the context definition of this action.

Overrides RulesActionBase::autoSaveContext

File

src/Plugin/RulesAction/DataSet.php, line 50

Class

DataSet
Provides a 'Data set' action.

Namespace

Drupal\rules\Plugin\RulesAction

Code

public function autoSaveContext() {

  // Saving is done at the root of the typed data tree, for example on the
  // entity level.
  $typed_data = $this
    ->getContext('data')
    ->getContextData();
  $root = $typed_data
    ->getRoot();
  $value = $root
    ->getValue();

  // Only save things that are objects and have a save() method.
  if (is_object($value) && method_exists($value, 'save')) {
    return [
      'data',
    ];
  }
  return [];
}