You are here

public function YamlFormThirdPartySettingsManager::afterBuild in YAML Form 8

Form element #after_build callback: Checks for 'third_party_settings'.

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 YamlFormThirdPartySettingsManagerInterface::afterBuild

File

src/YamlFormThirdPartySettingsManager.php, line 113

Class

YamlFormThirdPartySettingsManager
Form third party settings manager.

Namespace

Drupal\yamlform

Code

public function afterBuild(array $form, FormStateInterface $form_state) {

  // If third party settings are empty.
  if (!isset($form['third_party_settings']) || !Element::children($form['third_party_settings'])) {

    // Hide all actions including the 'Save configuration' button.
    $form['actions']['#access'] = FALSE;

    // Display a warning.
    drupal_set_message($this
      ->t('There are no third party settings available. Please install a contributed module that integrates with the YAML Form module.'), 'warning');

    // Link to supported Third party settings modules.
    $form['supported'] = [
      'title' => [
        '#markup' => $this
          ->t('Supported modules.'),
        '#prefix' => '<h3>',
        '#suffix' => '</h3>',
      ],
      'modules' => [
        '#theme' => 'admin_block_content',
        '#content' => $this->addonsManager
          ->getThirdPartySettings(),
      ],
    ];
  }
  else {
    ksort($form['third_party_settings']);
  }
  return $form;
}