You are here

public function FeatureContext::createPersonalizedElements in Acquia Lift Connector 7

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

@Given /^personalized elements:$/

File

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

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 = array();

    // Grab explicit targeting values if specified.
    if (!empty($option_set->targeting)) {
      $contexts = variable_get('personalize_url_querystring_contexts', array());
      if (isset($contexts[$option_set->targeting])) {
        foreach ($contexts[$option_set->targeting] as $value) {
          $context_values[] = $option_set->targeting . '::' . $value;
        }
      }
    }
    foreach ($content_options as $index => $content) {
      $content = trim($content);
      $option = array(
        '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);
    personalize_agent_set_status($option_set->agent, PERSONALIZE_STATUS_RUNNING);
  }
}