You are here

public function FeatureContext::createPersonalizedElements in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 behat-tests/features/bootstrap/FeatureContext.php \FeatureContext::createPersonalizedElements()

@Given /^personalized elements:$/

File

behat-tests/features/bootstrap/FeatureContext.php, line 258

Class

FeatureContext
Defines application features from the specific context.

Code

public function createPersonalizedElements(TableNode $elementsTable) {
  foreach ($elementsTable
    ->getHash() as $optionSetHash) {
    $option_set = (object) $optionSetHash;
    $option_set->plugin = 'elements';
    $option_set->data = array(
      'personalize_elements_selector' => $option_set->selector,
      'personalize_elements_type' => $option_set->type,
    );
    $option_set->executor = 'personalizeElements';
    $content_options = explode(',', $option_set->content);
    $options = array();
    $context_values = empty($option_set->targeting) ? array() : $this
      ->convertContexts(explode(',', $option_set->targerting));
    foreach ($content_options as $index => $content) {
      $content = trim($content);
      $option = array(
        'option_id' => 'option-' . ($index + 1),
        'option_label' => personalize_generate_option_label($index),
        'personalize_elements_content' => $content,
      );

      // Set up fixed targeting if there's an available fixed targeting value.
      if (!empty($context_values)) {
        $option['fixed_targeting'] = array(
          array_shift($context_values),
        );
      }
      $options[] = $option;
    }
    $options = personalize_ensure_unique_option_ids($options);
    $control_option = array(
      'option_label' => PERSONALIZE_CONTROL_OPTION_LABEL,
      'option_id' => PERSONALIZE_CONTROL_OPTION_ID,
      'personalize_elements_content' => '',
    );
    array_unshift($options, $control_option);
    $option_set->options = $options;
    personalize_option_set_save($option_set);
  }
}