You are here

protected function TeamAppFormTrait::nonMemberApiProductAccessWarningElement in Apigee Edge 8

Renders a render element with a warning for non-members.

Parameters

array $form: Form render array.

\Drupal\Core\Form\FormStateInterface $form_state: Form state object.

Return value

array An associative array with a key 'non_member_api_product_access_warning' and its value is a status message element which may or may not contain a warning message.

2 calls to TeamAppFormTrait::nonMemberApiProductAccessWarningElement()
TeamAppCreateFormBase::alterFormWithApiProductElement in modules/apigee_edge_teams/src/Entity/Form/TeamAppCreateFormBase.php
Allows to alter the form after API products form element have been added.
TeamAppEditForm::form in modules/apigee_edge_teams/src/Entity/Form/TeamAppEditForm.php
Gets the actual form array to be built.

File

modules/apigee_edge_teams/src/Entity/Form/TeamAppFormTrait.php, line 178

Class

TeamAppFormTrait
Helper trait that contains team app (create/edit) form specific tweaks.

Namespace

Drupal\apigee_edge_teams\Entity\Form

Code

protected function nonMemberApiProductAccessWarningElement(array $form, FormStateInterface $form_state) : array {
  $element = [
    '#theme' => 'status_messages',
    '#message_list' => [],
    '#weight' => -100,
  ];
  if (!in_array($this
    ->getTeamName($form, $form_state), $this
    ->getTeamMembershipMananger()
    ->getTeams(\Drupal::currentUser()
    ->getEmail()))) {
    $element['#message_list']['warning'][] = t('You are not member of this @team. You may see @api_products here that a @team member can not see.', [
      '@team' => mb_strtolower($this
        ->getEntityTypeManager()
        ->getDefinition('team')
        ->getSingularLabel()),
      '@api_products' => $this
        ->getEntityTypeManager()
        ->getDefinition('api_product')
        ->getPluralLabel(),
    ]);
  }
  return [
    'non_member_api_product_access_warning' => $element,
  ];
}