You are here

class DevelopmentToolsAssemblerForm in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5

Same name and namespace in other branches
  1. 8.8 src/Form/DevelopmentToolsAssemblerForm.php \Drupal\varbase\Form\DevelopmentToolsAssemblerForm
  2. 8.4 src/Form/DevelopmentToolsAssemblerForm.php \Drupal\varbase\Form\DevelopmentToolsAssemblerForm
  3. 8.6 src/Form/DevelopmentToolsAssemblerForm.php \Drupal\varbase\Form\DevelopmentToolsAssemblerForm
  4. 8.7 src/Form/DevelopmentToolsAssemblerForm.php \Drupal\varbase\Form\DevelopmentToolsAssemblerForm
  5. 9.0.x src/Form/DevelopmentToolsAssemblerForm.php \Drupal\varbase\Form\DevelopmentToolsAssemblerForm

Defines form for selecting extra compoennts for the assembler to install.

Hierarchy

Expanded class hierarchy of DevelopmentToolsAssemblerForm

1 file declares its use of DevelopmentToolsAssemblerForm
varbase.profile in ./varbase.profile
Enables modules and site configuration for a Varbase site installation.

File

src/Form/DevelopmentToolsAssemblerForm.php, line 15

Namespace

Drupal\varbase\Form
View source
class DevelopmentToolsAssemblerForm extends FormBase {

  /**
   * The Drupal application root.
   *
   * @var string
   */
  protected $root;

  /**
   * The info parser service.
   *
   * @var \Drupal\Core\Extension\InfoParserInterface
   */
  protected $infoParser;

  /**
   * The form helper.
   *
   * @var \Drupal\varbase\AssemblerFormHelper
   */
  protected $formHelper;

  /**
   * Assembler Form constructor.
   *
   * @param string $root
   *   The Drupal application root.
   * @param InfoParserInterface $info_parser
   *   The info parser service.
   * @param TranslationInterface $translator
   *   The string translation service.
   * @param \Drupal\varbase\Form\FormHelper $form_helper
   *   The form helper.
   */
  public function __construct($root, InfoParserInterface $info_parser, TranslationInterface $translator, FormHelper $form_helper) {
    $this->root = $root;
    $this->infoParser = $info_parser;
    $this->stringTranslation = $translator;
    $this->formHelper = $form_helper;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('app.root'), $container
      ->get('info_parser'), $container
      ->get('string_translation'), $container
      ->get('varbase.form_helper'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'varbase_development_tool';
  }

  /**
   * {@inheritdoc}
   *
   * @return array
   *   Development tools modules.
   */
  public function buildForm(array $form, FormStateInterface $form_state, array &$install_state = NULL) {
    $form['#title'] = $this
      ->t('Development tools');
    $form['development_tools_introduction'] = [
      '#weight' => -1,
      '#prefix' => '<p>',
      '#markup' => $this
        ->t("If you're only evaluating Varbase, you don't need to install these tools. These tools are needed if you're a developer and you're installing Varbase to build a new site."),
      '#suffix' => '</p>',
    ];

    // Development tools.
    $developmentTools = ConfigBit::getList('configbit/development.tools.varbase.bit.yml', 'show_development_tools', TRUE, 'dependencies', 'profile', 'varbase');
    if (count($developmentTools)) {
      $form['development_tools'] = [
        '#type' => 'fieldset',
      ];
      foreach ($developmentTools as $development_tool_key => $development_tool_info) {
        $checkbox_title = '';
        $checkbox_description = '';
        $checkbox_selected = FALSE;
        if (isset($development_tool_info['title'])) {
          $checkbox_title = $development_tool_info['title'];
        }
        if (isset($development_tool_info['description'])) {
          $checkbox_description = $development_tool_info['description'];
        }
        if (isset($development_tool_info['selected'])) {
          $checkbox_selected = $development_tool_info['selected'];
        }

        // Have a checkbox to enable this development tool.
        $form['development_tools'][$development_tool_key] = [
          '#type' => 'checkbox',
          '#title' => $checkbox_title,
          '#description' => $checkbox_description,
          '#default_value' => $checkbox_selected,
        ];

        // If config_form is ture for this development tool.
        if (isset($development_tool_info['config_form']) && $development_tool_info['config_form'] == TRUE) {
          $form['development_tools'][$development_tool_key . '_config'] = [
            '#type' => 'fieldset',
            '#title' => $checkbox_title,
            '#states' => [
              'visible' => [
                ':input[name="' . $development_tool_key . '"]' => [
                  'checked' => TRUE,
                ],
              ],
              'invisible' => [
                ':input[name="' . $development_tool_key . '"]' => [
                  'checked' => FALSE,
                ],
              ],
            ],
          ];
          if (isset($development_tool_info['formbit'])) {
            $formbit_file_name = drupal_get_path('profile', 'varbase') . '/' . $development_tool_info['formbit'];
            if (file_exists($formbit_file_name)) {
              include_once $formbit_file_name;

              // Add configuration form element in the formbit position.
              call_user_func_array($development_tool_key . "_build_formbit", array(
                &$form['development_tools'][$development_tool_key . '_config'],
                &$form_state,
                &$install_state,
              ));
            }
          }
        }
      }
    }
    $form['actions'] = [
      'continue' => [
        '#type' => 'submit',
        '#value' => $this
          ->t('Continue'),
        '#button_type' => 'primary',
      ],
      '#type' => 'actions',
      '#weight' => 5,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    // Development Tools.
    $developmentTools = ConfigBit::getList('configbit/development.tools.varbase.bit.yml', 'show_development_tools', TRUE, 'dependencies', 'profile', 'varbase');
    if (count($developmentTools)) {
      $development_tools_values = [];
      foreach ($developmentTools as $development_tool_key => $development_tool_info) {

        // If form state has got value for this development tool.
        if ($form_state
          ->hasValue($development_tool_key)) {
          $development_tools_values[$development_tool_key] = $form_state
            ->getValue($development_tool_key);
        }
        if (isset($development_tool_info['config_form']) && $development_tool_info['config_form'] == TRUE) {
          $formbit_file_name = drupal_get_path('profile', 'varbase') . '/' . $development_tool_info['formbit'];
          if (file_exists($formbit_file_name)) {
            include_once $formbit_file_name;
            $development_tools_editable_configs = call_user_func_array($development_tool_key . "_get_editable_config_names", array());
            if (count($development_tools_editable_configs)) {
              foreach ($development_tools_editable_configs as $development_tools_editable_config_key => $development_tools_editable_config) {
                foreach ($development_tools_editable_config as $development_tools_config_item_key => $development_tools_config_item_value) {
                  if ($form_state
                    ->hasValue($development_tools_config_item_key)) {
                    $development_tools_editable_configs[$development_tools_editable_config_key][$development_tools_config_item_key] = $form_state
                      ->getValue($development_tools_config_item_key);
                  }
                }
              }
            }
            $GLOBALS['install_state']['varbase']['development_tools_configs'] = $development_tools_editable_configs;
          }
        }
      }
      $GLOBALS['install_state']['varbase']['development_tools_values'] = $development_tools_values;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DevelopmentToolsAssemblerForm::$formHelper protected property The form helper.
DevelopmentToolsAssemblerForm::$infoParser protected property The info parser service.
DevelopmentToolsAssemblerForm::$root protected property The Drupal application root.
DevelopmentToolsAssemblerForm::buildForm public function Overrides FormInterface::buildForm
DevelopmentToolsAssemblerForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
DevelopmentToolsAssemblerForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
DevelopmentToolsAssemblerForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
DevelopmentToolsAssemblerForm::__construct public function Assembler Form constructor.
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.