You are here

public function NotificationsWidgetSettingsForm::prepareEntityTypeForm in Notifications widget 8

1 call to NotificationsWidgetSettingsForm::prepareEntityTypeForm()
NotificationsWidgetSettingsForm::buildForm in src/Form/NotificationsWidgetSettingsForm.php
Build form.

File

src/Form/NotificationsWidgetSettingsForm.php, line 215

Class

NotificationsWidgetSettingsForm
Provides settings for Notification widget module.

Namespace

Drupal\notifications_widget\Form

Code

public function prepareEntityTypeForm($nodeType, $nodeTypeName, $config, $entityName) {
  $form = [];
  $form[$nodeType] = [
    '#type' => 'details',
    '#title' => $this
      ->t('@entityName Type - @nodeTypeName', [
      '@entityName' => $entityName,
      '@nodeTypeName' => $nodeTypeName,
    ]),
    '#open' => FALSE,
  ];
  $contentDefaultUrl = '[entity:url]';
  $contentTypeEnable = $nodeType . '_enable';
  $contentCreateDefault = $nodeType . '_noti_create_message';
  $contentUpdateDefault = $nodeType . '_noti_update_message';
  $contentDeleteDefault = $nodeType . '_noti_delete_message';
  $contentDefaultSettngs = $config
    ->get($contentTypeEnable);
  $contentCreateDefaultValue = $config
    ->get($contentCreateDefault);
  $contentUpdateDefaultValue = $config
    ->get($contentUpdateDefault);
  $contentDeleteDefaultValue = $config
    ->get($contentDeleteDefault);
  $contentConfStatus = $config
    ->get('notfication_widget_conf');

  /*
   * Configure & set default values.
   */
  if (empty($contentDefaultSettngs) && $contentConfStatus != 1) {
    $contentDefaultValues = [
      'Create',
      'Update',
      'Delete',
    ];
  }
  else {
    $contentDefaultValues = explode(',', $contentDefaultSettngs);
  }
  if (empty($contentCreateDefaultValue)) {
    $contentCreateDefaultValue = $this
      ->t('@nodeTypeName has been created by [user:name]', [
      '@nodeTypeName' => $nodeTypeName,
    ]);
  }
  if (empty($contentUpdateDefaultValue)) {
    $contentUpdateDefaultValue = $this
      ->t('@nodeTypeName has been updated by [user:name]', [
      '@nodeTypeName' => $nodeTypeName,
    ]);
  }
  if (empty($contentDeleteDefaultValue)) {
    $contentDeleteDefaultValue = $this
      ->t('@nodeTypeName has been deleted by [user:name]', [
      '@nodeTypeName' => $nodeTypeName,
    ]);
  }
  $form[$nodeType][$contentTypeEnable] = [
    '#type' => 'checkboxes',
    '#options' => [
      'Create' => 'Create',
      'Update' => 'Update',
      'Delete' => 'Delete',
    ],
    '#title' => 'Notification logs enable',
    '#default_value' => $contentDefaultValues,
  ];
  $form[$nodeType][$nodeType . '_noti_create_message'] = [
    '#type' => 'textfield',
    '#title' => 'Create Notification Message',
    '#default_value' => $contentCreateDefaultValue,
  ];
  $form[$nodeType][$nodeType . '_redirect_create_link'] = [
    '#type' => 'textfield',
    '#title' => 'Create Notification Message URL',
    '#description' => $this
      ->t('The url, path for this notification to link. Leave blank if no link is required.'),
    '#default_value' => is_null($config
      ->get($nodeType . '_redirect_create_link')) ? $contentDefaultUrl : $config
      ->get($nodeType . '_redirect_create_link'),
  ];
  $form[$nodeType][$nodeType . '_noti_update_message'] = [
    '#type' => 'textfield',
    '#title' => 'Update Notification Message',
    '#default_value' => $contentUpdateDefaultValue,
  ];
  $form[$nodeType][$nodeType . '_redirect_update_link'] = [
    '#type' => 'textfield',
    '#title' => 'Update Notification Message URL',
    '#description' => $this
      ->t('The url, path for this notification to link. Leave blank if no link is required.'),
    '#default_value' => is_null($config
      ->get($nodeType . '_redirect_update_link')) ? $contentDefaultUrl : $config
      ->get($nodeType . '_redirect_update_link'),
  ];
  $form[$nodeType][$nodeType . '_noti_delete_message'] = [
    '#type' => 'textfield',
    '#title' => 'Delete Notification Message',
    '#default_value' => $contentDeleteDefaultValue,
  ];
  $form[$nodeType][$nodeType . '_redirect_delete_link'] = [
    '#type' => 'textfield',
    '#title' => 'Delete Notification Message URL',
    '#description' => $this
      ->t('The url, path for this notification to link. Leave blank if no link is required.'),
    '#default_value' => is_null($config
      ->get($nodeType . '_redirect_delete_link')) ? $contentDefaultUrl : $config
      ->get($nodeType . '_redirect_delete_link'),
  ];
  return $form;
}