You are here

public function GroupAddForm::groupExists in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/Form/GroupAddForm.php \Drupal\context_groups\Form\GroupAddForm::groupExists()

Check to see if group with the specified name already exists .

Parameters

string $name: The machine name to check for.

array $element: Machine name form element.

FormStateInterface $form_state: Formstate object.

Return value

bool True or false.

File

src/Form/GroupAddForm.php, line 201

Class

GroupAddForm
Class GroupDeleteForm.

Namespace

Drupal\context_groups\Form

Code

public function groupExists($name, array $element, FormStateInterface $form_state) {

  // Get all contexts.
  $query = $this->entityTypeManager
    ->getStorage('context')
    ->getQuery();
  $context_ids = $query
    ->execute();
  $context_storage = $this->entityTypeManager
    ->getStorage('context');
  foreach ($context_ids as $cid) {
    $context = $context_storage
      ->load($cid);
    $groups = $context
      ->getThirdPartySetting('context_groups', $name);
    if (!empty($groups)) {
      return TRUE;
    }
  }
  return FALSE;
}