You are here

public function GroupContentTypeForm::form in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Form/GroupContentTypeForm.php \Drupal\group\Entity\Form\GroupContentTypeForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Entity/Form/GroupContentTypeForm.php, line 68

Class

GroupContentTypeForm
Form controller for group content type forms.

Namespace

Drupal\group\Entity\Form

Code

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

  /** @var \Drupal\group\Entity\GroupContentTypeInterface $group_content_type */
  $group_content_type = $this
    ->getEntity();
  $group_type = $group_content_type
    ->getGroupType();
  $plugin = $this
    ->getContentPlugin();

  // @todo These messages may need some love.
  if ($this->operation == 'add') {
    $form['#title'] = $this
      ->t('Install content plugin');
    $message = 'By installing the %plugin plugin, you will allow %entity_type entities to be added to groups of type %group_type';
  }
  else {
    $form['#title'] = $this
      ->t('Configure content plugin');
    $message = 'This form allows you to configure the %plugin plugin for the %group_type group type.';
  }

  // Add in the replacements for the $message variable set above.
  $replace = [
    '%plugin' => $plugin
      ->getLabel(),
    '%entity_type' => $this->entityTypeManager
      ->getDefinition($plugin
      ->getEntityTypeId())
      ->getLabel(),
    '%group_type' => $group_type
      ->label(),
  ];

  // Display a description to explain the purpose of the form.
  $form['description'] = [
    '#markup' => $this
      ->t($message, $replace),
  ];

  // Add in the plugin configuration form.
  $form += $plugin
    ->buildConfigurationForm($form, $form_state);
  return $form;
}