You are here

function acquia_lift_form_personalize_blocks_form_alter in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift.module \acquia_lift_form_personalize_blocks_form_alter()

Implements hook_form_FORM_ID_alter().

File

./acquia_lift.module, line 2767
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function acquia_lift_form_personalize_blocks_form_alter(&$form, &$form_state) {
  $form['#submit'][] = 'acquia_lift_personalize_blocks_form_submit';
  if (!isset($form['agent_select']['#value'])) {
    return;
  }
  module_load_include('inc', 'acquia_lift', 'acquia_lift.admin');
  $agent = $form['agent_select']['#value'];
  $agent_data = personalize_agent_load($agent);
  if (!acquia_lift_target_definition_changes_allowed($agent_data)) {
    $show_remove_message = FALSE;
    foreach (element_children($form['pblock_wrapper']['blocks']) as $delta) {
      $option_id = $form['pblock_wrapper']['blocks'][$delta]['option_id']['#value'];
      if (acquia_lift_target_option_targeted($agent, $option_id)) {
        $form['pblock_wrapper']['blocks'][$delta]['remove']['#access'] = FALSE;
        $show_remove_message = TRUE;
      }
    }
    if ($show_remove_message) {
      drupal_set_message(t('Variations in use cannot be removed from %variation_set until the %agent_name personalization is paused.', array(
        '%variation_set' => $form['title']['#default_value'],
        '%agent_name' => $agent_data->label,
      )), 'warning');
    }
  }
}