You are here

public function GroupContentEnablerBase::buildConfigurationForm in Group 8

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

2 calls to GroupContentEnablerBase::buildConfigurationForm()
GroupMembership::buildConfigurationForm in src/Plugin/GroupContentEnabler/GroupMembership.php
Form constructor.
GroupNode::buildConfigurationForm in modules/gnode/src/Plugin/GroupContentEnabler/GroupNode.php
Form constructor.
2 methods override GroupContentEnablerBase::buildConfigurationForm()
GroupMembership::buildConfigurationForm in src/Plugin/GroupContentEnabler/GroupMembership.php
Form constructor.
GroupNode::buildConfigurationForm in modules/gnode/src/Plugin/GroupContentEnabler/GroupNode.php
Form constructor.

File

src/Plugin/GroupContentEnablerBase.php, line 495

Class

GroupContentEnablerBase
Provides a base class for GroupContentEnabler plugins.

Namespace

Drupal\group\Plugin

Code

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

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $replace = [
    '%entity_type' => $entity_type_manager
      ->getDefinition($this
      ->getEntityTypeId())
      ->getLabel(),
    '%group_type' => $this
      ->getGroupType()
      ->label(),
    '%plugin' => $this
      ->getLabel(),
  ];
  $form['group_cardinality'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Group cardinality'),
    '#description' => $this
      ->t('The amount of %group_type groups a single %entity_type entity can be added to as a %plugin. Set to 0 for unlimited.', $replace),
    '#default_value' => $this->configuration['group_cardinality'],
    '#min' => 0,
    '#required' => TRUE,
  ];
  $form['entity_cardinality'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Entity cardinality'),
    '#description' => $this
      ->t('The amount of times a single %entity_type entity can be added to the same %group_type group as a %plugin. Set to 0 for unlimited.', $replace),
    '#default_value' => $this->configuration['entity_cardinality'],
    '#min' => 0,
    '#required' => TRUE,
  ];
  if ($this
    ->definesEntityAccess()) {
    $form['use_creation_wizard'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Use 2-step wizard when creating a new %entity_type entity within a %group_type group', $replace),
      '#description' => $this
        ->t('This will first show you the form to create the actual entity and then a form to create the relationship between the entity and the group.<br />You can choose to disable this wizard if you did not or will not add any fields to the relationship (i.e. this plugin).<br /><strong>Warning:</strong> If you do have fields on the relationship and do not use the wizard, you may end up with required fields not being filled out.'),
      '#default_value' => $this->configuration['use_creation_wizard'],
    ];
  }
  return $form;
}