You are here

function entity_share_async_form_entity_share_client_pull_form_alter in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 modules/entity_share_async/entity_share_async.module \entity_share_async_form_entity_share_client_pull_form_alter()

Implements hook_form_FORM_ID_alter().

File

modules/entity_share_async/entity_share_async.module, line 15

Code

function entity_share_async_form_entity_share_client_pull_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $async_button = [
    '#type' => 'submit',
    '#value' => t('Import asynchronously'),
    '#button_type' => 'primary',
    '#submit' => [
      '_entity_share_async_form_submit',
    ],
  ];

  // Add buttons.
  if (isset($form['channel_wrapper']['entities_wrapper']['actions_top'])) {
    $form['channel_wrapper']['entities_wrapper']['actions_top']['async'] = $async_button;
  }
  if (isset($form['channel_wrapper']['entities_wrapper']['actions_bottom'])) {
    $form['channel_wrapper']['entities_wrapper']['actions_bottom']['async'] = $async_button;
  }

  // Alter the entities table select.
  if (isset($form['channel_wrapper']['entities_wrapper']['entities'])) {
    $state_storage = \Drupal::state();
    $request = \Drupal::request();
    $async_states = $state_storage
      ->get('entity_share_async.states', []);
    $remote_id = $form_state
      ->getValue('remote', $request
      ->get('remote'));
    $channel_id = $form_state
      ->getValue('channel', $request
      ->get('channel'));
    foreach ($form['channel_wrapper']['entities_wrapper']['entities']['#options'] as $uuid => $values) {
      if (isset($async_states[$remote_id][$channel_id][$uuid])) {
        $form['channel_wrapper']['entities_wrapper']['entities']['#options'][$uuid]['#attributes']['class'] = [
          'entity-share-waiting-sync',
        ];
        $form['channel_wrapper']['entities_wrapper']['entities']['#options'][$uuid]['status'] = t('Waiting for synchronization');
      }
    }
  }
}