class WebformCiviCRMSettingsForm in Webform CiviCRM Integration 8.5
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\webform_civicrm\Form\WebformCiviCRMSettingsForm
 
 
Expanded class hierarchy of WebformCiviCRMSettingsForm
1 string reference to 'WebformCiviCRMSettingsForm'
File
- src/
Form/ WebformCiviCRMSettingsForm.php, line 13  
Namespace
Drupal\webform_civicrm\FormView source
class WebformCiviCRMSettingsForm extends FormBase {
  protected $webformHandlerManager;
  public function __construct(RouteMatchInterface $route_match, WebformHandlerManagerInterface $webform_handler_manager) {
    $this->routeMatch = $route_match;
    $this->webformHandlerManager = $webform_handler_manager;
  }
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('current_route_match'), $container
      ->get('plugin.manager.webform.handler'));
  }
  /**
   * @return \Drupal\webform\WebformInterface
   */
  public function getWebform() {
    return $this->routeMatch
      ->getParameter('webform');
  }
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'webform_civicrm_settings_form';
  }
  /**
   * {@inheritdoc}
   *
   * @todo slowly move parts of the D7 handling into here.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $webform = $this
      ->getWebform();
    $admin_form = \Drupal::service('webform_civicrm.admin_form')
      ->initialize($form, $form_state, $webform);
    $form = $admin_form
      ->buildForm();
    return $form;
  }
  /**
   * {@inheritdoc}
   *
   * @todo find a more elegant way to handle the handler creation/removal.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $webform = $this
      ->getWebform();
    $handler_collection = $webform
      ->getHandlers('webform_civicrm');
    $values = $form_state
      ->getValues();
    // Check if this is the confirmation form for removed fields.
    if (!isset($values['nid']) && isset($values['delete'], $values['disable'], $values['cancel'])) {
      $triggering_element = $form_state
        ->getTriggeringElement();
      if ($triggering_element['#parents'][0] === 'cancel') {
        $this
          ->messenger()
          ->addMessage('Cancelled');
        return;
      }
      if ($triggering_element['#parents'][0] === 'delete') {
        // Restore the form state values.
        $values += $form_state
          ->get('vals') ?: [];
        $form_state
          ->setValues($values);
      }
      if ($triggering_element['#parents'][0] === 'disable') {
        // @todo probably restore as well, but flag later on not to delete.
        $this
          ->messenger()
          ->addMessage('Disable is not yet supported, canceled form save.');
        return;
      }
    }
    $has_handler = $handler_collection
      ->has('webform_civicrm');
    $remove_handler = empty($values['nid']);
    if (!$has_handler && $remove_handler) {
      $this
        ->messenger()
        ->addWarning('No changes made to CiviCRM settings');
      return;
    }
    /** @var \Drupal\webform\Plugin\WebformHandlerInterface $handler */
    if (!$has_handler) {
      $handler = $this->webformHandlerManager
        ->createInstance('webform_civicrm');
      $handler
        ->setWebform($webform);
      $handler
        ->setHandlerId('webform_civicrm');
      $handler
        ->setStatus(TRUE);
      $webform
        ->addWebformHandler($handler);
    }
    else {
      $handler = $handler_collection
        ->get('webform_civicrm');
    }
    if ($remove_handler) {
      $webform
        ->deleteWebformHandler($handler);
      $this
        ->messenger()
        ->addMessage('Removed CiviCRM');
      return;
    }
    $admin_form = \Drupal::service('webform_civicrm.admin_form')
      ->initialize($form, $form_state, $webform);
    $form_state
      ->cleanValues();
    $admin_form
      ->setSettings($form_state
      ->getValues());
    $admin_form
      ->rebuildData();
    $settings = $admin_form
      ->getSettings();
    $handler_configuration = $handler
      ->getConfiguration();
    $handler_configuration['settings'] = $settings;
    $handler
      ->setConfiguration($handler_configuration);
    $admin_form
      ->postProcess();
    if (empty($admin_form->confirmPage)) {
      $webform
        ->save();
      $this
        ->messenger()
        ->addMessage('Saved CiviCRM settings');
    }
  }
  /**
   * AJAX callback for elements with a pathstr.
   *
   * @param array $form
   *   The complete form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   *
   * @return array
   *   The form element to refresh.
   */
  public static function pathstrAjaxRefresh(array &$form, FormStateInterface $form_state) {
    $triggering_element = $form_state
      ->getTriggeringElement();
    $element = NestedArray::getValue($form, explode(':', $triggering_element['#ajax']['pathstr']));
    return $element;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of entity type IDs keyed by the property name of their storages. | |
| 
            DependencySerializationTrait:: | 
                  protected | property | An array of service IDs keyed by property name used for serialization. | |
| 
            DependencySerializationTrait:: | 
                  public | function | 1 | |
| 
            DependencySerializationTrait:: | 
                  public | function | 2 | |
| 
            FormBase:: | 
                  protected | property | The config factory. | 1 | 
| 
            FormBase:: | 
                  protected | property | The request stack. | 1 | 
| 
            FormBase:: | 
                  protected | property | The route match. | |
| 
            FormBase:: | 
                  protected | function | Retrieves a configuration object. | |
| 
            FormBase:: | 
                  protected | function | Gets the config factory for this form. | 1 | 
| 
            FormBase:: | 
                  private | function | Returns the service container. | |
| 
            FormBase:: | 
                  protected | function | Gets the current user. | |
| 
            FormBase:: | 
                  protected | function | Gets the request object. | |
| 
            FormBase:: | 
                  protected | function | Gets the route match. | |
| 
            FormBase:: | 
                  protected | function | Gets the logger for a specific channel. | |
| 
            FormBase:: | 
                  protected | function | 
            Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: | 
                  |
| 
            FormBase:: | 
                  public | function | Resets the configuration factory. | |
| 
            FormBase:: | 
                  public | function | Sets the config factory for this form. | |
| 
            FormBase:: | 
                  public | function | Sets the request stack object to use. | |
| 
            FormBase:: | 
                  public | function | 
            Form validation handler. Overrides FormInterface:: | 
                  62 | 
| 
            LinkGeneratorTrait:: | 
                  protected | property | The link generator. | 1 | 
| 
            LinkGeneratorTrait:: | 
                  protected | function | Returns the link generator. | |
| 
            LinkGeneratorTrait:: | 
                  protected | function | Renders a link to a route given a route name and its parameters. | |
| 
            LinkGeneratorTrait:: | 
                  public | function | Sets the link generator service. | |
| 
            LoggerChannelTrait:: | 
                  protected | property | The logger channel factory service. | |
| 
            LoggerChannelTrait:: | 
                  protected | function | Gets the logger for a specific channel. | |
| 
            LoggerChannelTrait:: | 
                  public | function | Injects the logger channel factory. | |
| 
            MessengerTrait:: | 
                  protected | property | The messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Gets the messenger. | 29 | 
| 
            MessengerTrait:: | 
                  public | function | Sets the messenger. | |
| 
            RedirectDestinationTrait:: | 
                  protected | property | The redirect destination service. | 1 | 
| 
            RedirectDestinationTrait:: | 
                  protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
| 
            RedirectDestinationTrait:: | 
                  protected | function | Returns the redirect destination service. | |
| 
            RedirectDestinationTrait:: | 
                  public | function | Sets the redirect destination service. | |
| 
            StringTranslationTrait:: | 
                  protected | property | The string translation service. | 1 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Formats a string containing a count of items. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Returns the number of plurals supported by a given language. | |
| 
            StringTranslationTrait:: | 
                  protected | function | Gets the string translation service. | |
| 
            StringTranslationTrait:: | 
                  public | function | Sets the string translation service to use. | 2 | 
| 
            StringTranslationTrait:: | 
                  protected | function | Translates a string to the current language or to a given language. | |
| 
            UrlGeneratorTrait:: | 
                  protected | property | The url generator. | |
| 
            UrlGeneratorTrait:: | 
                  protected | function | Returns the URL generator service. | |
| 
            UrlGeneratorTrait:: | 
                  public | function | Sets the URL generator service. | |
| 
            UrlGeneratorTrait:: | 
                  protected | function | Generates a URL or path for a specific route based on the given parameters. | |
| 
            WebformCiviCRMSettingsForm:: | 
                  protected | property | ||
| 
            WebformCiviCRMSettingsForm:: | 
                  public | function | 
            @todo slowly move parts of the D7 handling into here. Overrides FormInterface:: | 
                  |
| 
            WebformCiviCRMSettingsForm:: | 
                  public static | function | 
            Instantiates a new instance of this class. Overrides FormBase:: | 
                  |
| 
            WebformCiviCRMSettingsForm:: | 
                  public | function | 
            Returns a unique string identifying the form. Overrides FormInterface:: | 
                  |
| 
            WebformCiviCRMSettingsForm:: | 
                  public | function | ||
| 
            WebformCiviCRMSettingsForm:: | 
                  public static | function | AJAX callback for elements with a pathstr. | |
| 
            WebformCiviCRMSettingsForm:: | 
                  public | function | 
            @todo find a more elegant way to handle the handler creation/removal. Overrides FormInterface:: | 
                  |
| 
            WebformCiviCRMSettingsForm:: | 
                  public | function |