You are here

function activity_logger_form_message_template_form_alter in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  2. 8 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  3. 8.2 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  4. 8.3 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  5. 8.4 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  6. 8.5 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  7. 8.6 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  8. 8.7 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  9. 8.8 modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  10. 10.3.x modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  11. 10.1.x modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()
  12. 10.2.x modules/custom/activity_logger/activity_logger.module \activity_logger_form_message_template_form_alter()

Implements hook_form_FORM_ID_alter() for message_template_form().

File

modules/custom/activity_logger/activity_logger.module, line 57
Contains activity_logger.module..

Code

function activity_logger_form_message_template_form_alter(&$form, FormStateInterface $form_state) {

  /** @var \Drupal\message\MessageTemplateInterface $message_template */
  $message_template = $form_state
    ->getFormObject()
    ->getEntity();
  $wrapper_id = 'edit-activity-entity-condition-ajax-wrapper';
  $config_entity_bundles = _activity_logger_get_content_entities();
  $form['activity_bundle_entities'] = [
    '#type' => 'select',
    '#required' => TRUE,
    '#multiple' => TRUE,
    '#title' => t('The entities that are affected for this message'),
    '#description' => t('Select a entity bundle type to for this message.'),
    '#default_value' => $message_template
      ->getThirdPartySetting('activity_logger', 'activity_bundle_entities', NULL),
    '#options' => $config_entity_bundles,
    '#ajax' => [
      'callback' => '_activity_logger_form_message_template_entity_ajax_callback',
      'wrapper' => $wrapper_id,
    ],
  ];
  $form['activity_entity_condition_wrapper'] = [
    '#type' => 'container',
    '#attributes' => [
      'id' => $wrapper_id,
    ],
  ];
  $activity_bundle_entities = $form_state
    ->getValue('activity_bundle_entities');
  if (empty($activity_bundle_entities)) {
    $activity_bundle_entities = $message_template
      ->getThirdPartySetting('activity_logger', 'activity_bundle_entities', []);
  }
  $activity_entity_condition_options = \Drupal::service('plugin.manager.activity_entity_condition.processor');
  $activity_entity_condition_options = $activity_entity_condition_options
    ->getOptionsList($activity_bundle_entities);
  if (empty($activity_entity_condition_options)) {
    $activity_entity_condition_value = NULL;
  }
  else {
    $activity_entity_condition_value = $message_template
      ->getThirdPartySetting('activity_logger', 'activity_entity_condition', NULL);
  }
  $form['activity_entity_condition_wrapper']['activity_entity_condition'] = [
    '#type' => 'select',
    '#title' => t('The entity condition that are affected for this message'),
    '#description' => t('Select a entity condition for this message.'),
    '#default_value' => $activity_entity_condition_value,
    '#options' => $activity_entity_condition_options,
    '#access' => !empty($activity_entity_condition_options),
  ];
  $activity_actions = \Drupal::service('plugin.manager.activity_action.processor');
  $activity_actions = $activity_actions
    ->getOptionsList();
  $form['activity_action'] = [
    '#type' => 'select',
    '#required' => TRUE,
    '#title' => t('The activity actions for this message'),
    '#description' => t('Select a action for when to display this message.'),
    '#default_value' => $message_template
      ->getThirdPartySetting('activity_logger', 'activity_action', NULL),
    '#options' => $activity_actions,
  ];
  $activity_recipient_manager = \Drupal::service('plugin.manager.activity_context.processor');
  $context_options = $activity_recipient_manager
    ->getOptionsList();
  $form['activity_context'] = [
    '#type' => 'select',
    '#required' => TRUE,
    '#title' => t('The activity context for this message'),
    '#description' => t('Select a context where to display this message.'),
    '#default_value' => $message_template
      ->getThirdPartySetting('activity_logger', 'activity_context', NULL),
    '#options' => $context_options,
  ];
  $activity_recipient_manager = \Drupal::service('plugin.manager.activity_destination.processor');
  $destination_options = $activity_recipient_manager
    ->getOptionsList();
  $form['activity_destinations'] = [
    '#type' => 'select',
    '#title' => t('The activity destinations for this message'),
    '#multiple' => TRUE,
    '#required' => TRUE,
    '#description' => t('Select destinations where to display this message.'),
    '#default_value' => $message_template
      ->getThirdPartySetting('activity_logger', 'activity_destinations', NULL),
    // @todo activity_creator allowed_values function overlap (should be plugin)
    '#options' => $destination_options,
  ];
  $form['activity_create_direct'] = [
    '#type' => 'checkbox',
    '#required' => FALSE,
    '#title' => t('Create activity items direct instead of in Queue'),
    '#description' => t('Select if items should be created directly instead of in the queue. Warning: performance implications!'),
    '#default_value' => $message_template
      ->getThirdPartySetting('activity_logger', 'activity_create_direct', NULL),
  ];
  $form['#entity_builders'][] = 'activity_logger_form_message_template_form_builder';
  $form['activity_aggregate'] = [
    '#type' => 'checkbox',
    '#required' => FALSE,
    '#title' => t('Aggregate activity'),
    '#description' => t('Select if items should be aggregated instead of displaying separately.'),
    '#default_value' => $message_template
      ->getThirdPartySetting('activity_logger', 'activity_aggregate', NULL),
  ];

  // Add titles to output text fields for clarity.
  if (isset($form['text'][0])) {
    $form['text'][0]['#title'] = t('Output text for normal activities in activity stream');
  }
  if (isset($form['text'][1])) {
    $form['text'][1]['#title'] = t('Output text for aggregated items in activity stream');
  }
  if (isset($form['text'][2])) {
    $form['text'][2]['#title'] = t('Output text for email notifications');
  }
}