You are here

public function GroupEditForm::buildForm in Paragraphs Browser 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 FormInterface::buildForm

File

src/Form/GroupEditForm.php, line 40
Contains \Drupal\paragraphs_browser\Form\GroupEditForm.

Class

GroupEditForm
Class CleanupUrlAliases.

Namespace

Drupal\paragraphs_browser\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, BrowserTypeInterface $paragraphs_browser_type = null, $group_machine_name = '') {

  /** @var BrowserType $paragraphs_browser_type */
  $this->entity = $paragraphs_browser_type;

  /** @var BrowserGroupList $groups */
  $groups = $paragraphs_browser_type
    ->groupManager();

  // Build the form.
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $groups
      ->getGroup($group_machine_name)
      ->getLabel(),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $group_machine_name,
    '#machine_name' => array(
      'exists' => array(
        $this,
        'exists',
      ),
      'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
      'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".',
    ),
    '#disabled' => TRUE,
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
    '#submit' => array(
      '::submitForm',
      '::save',
    ),
  );
  return $form;
}