You are here

public function AcquiadamConfig::buildForm in Media: Acquia DAM 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/AcquiadamConfig.php, line 79

Class

AcquiadamConfig
Class AcquiadamConfig.

Namespace

Drupal\media_acquiadam\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('media_acquiadam.settings');
  $form['authentication'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Authentication details'),
  ];
  $form['authentication']['username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Username'),
    '#default_value' => $config
      ->get('username'),
    '#description' => $this
      ->t('The username of the Acquia DAM account to use for API access.'),
    '#required' => TRUE,
  ];
  $form['authentication']['password'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Password'),
    '#default_value' => $config
      ->get('password'),
    '#description' => $this
      ->t('The password of the Acquia DAM account to use for API access. Note that this field will appear blank even if you have previously saved a value.'),
  ];
  $form['authentication']['client_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Client ID'),
    '#default_value' => $config
      ->get('client_id'),
    '#description' => $this
      ->t('API Client ID to use for API access. Contact the Acquia DAM support team to get one assigned.'),
    '#required' => TRUE,
  ];
  $form['authentication']['secret'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Client secret'),
    '#default_value' => $config
      ->get('secret'),
    '#description' => $this
      ->t('API Client Secret to use for API access. Contact the Acquia DAM support team to get one assigned. Note that this field will appear blank even if you have previously saved a value.'),
  ];
  $form['cron'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Cron Settings'),
  ];
  $form['cron']['sync_interval'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Asset refresh interval'),
    '#options' => [
      '-1' => 'Every cron run',
      '3600' => 'Every hour',
      '7200' => 'Every 2 hours',
      '10800' => 'Every 3 hours',
      '14400' => 'Every 4 hours',
      '21600' => 'Every 6 hours',
      '28800' => 'Every 8 hours',
      '43200' => 'Every 12 hours',
      '86400' => 'Every 24 hours',
    ],
    '#default_value' => empty($config
      ->get('sync_interval')) ? 3600 : $config
      ->get('sync_interval'),
    '#description' => $this
      ->t('How often should Acquia DAM assets saved in this site be synced with Acquia DAM (this includes asset metadata as well as the asset itself)?'),
    '#required' => TRUE,
  ];
  $form['cron']['notifications_sync'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable notification-based synchronization'),
    '#description' => $this
      ->t('Faster synchronization method based on Notifications from the API.'),
    '#default_value' => $config
      ->get('notifications_sync'),
  ];
  $form['cron']['perform_sync_delete'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Delete inactive drupal dam assets.'),
    '#default_value' => $config
      ->get('perform_sync_delete'),
    '#description' => $this
      ->t('Deletes unpublished drupal media entities if DAM asset is not available.'),
  ];
  $form['image'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Image configuration'),
  ];
  $form['image']['size_limit'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image size limit'),
    '#description' => $this
      ->t('Limit the source size used when importing image assets. The largest available size up to the selected will be used.'),
    '#options' => [
      -1 => $this
        ->t('Original size'),
      100 => 100,
      150 => 150,
      220 => 220,
      310 => 310,
      550 => 550,
      1280 => 1280,
    ],
    '#default_value' => empty($config
      ->get('size_limit')) ? -1 : $config
      ->get('size_limit'),
  ];
  $form['manual_sync'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Manual asset synchronization.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  ];
  $form['manual_sync']['perform_manual_sync'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Synchronize all media assets'),
    '#name' => 'perform_manual_sync',
    '#submit' => [
      [
        $this,
        'performManualSync',
      ],
    ],
  ];
  $form['entity_browser'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Acquia DAM entity browser settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];
  $form['entity_browser']['num_images_per_page'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Number of images per page'),
    '#default_value' => $config
      ->get('num_images_per_page') ?? self::NUM_IMAGES_PER_PAGE,
    '#description' => $this
      ->t('Number of images to be shown per page in the entity browser can be set using this field. Default is set to 12 images.'),
    '#required' => TRUE,
  ];
  $form['entity_browser']['samesite_cookie_disable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable SameSite Cookie Bypass'),
    '#description' => $this
      ->t('Checking this box will effectively disable authentication from working within the Entity Browser. See Acquia Documentation for more details.'),
    '#default_value' => $config
      ->get('samesite_cookie_disable') ?? 0,
  ];
  return parent::buildForm($form, $form_state);
}