You are here

public function WorkflowStateListBuilder::exists in Workflow 8

Validate duplicate machine names.

Function is registered in 'machine_name' form element.

Parameters

string $name:

array $element:

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

bool

File

src/WorkflowStateListBuilder.php, line 400

Class

WorkflowStateListBuilder
Defines a class to build a draggable listing of Workflow State entities.

Namespace

Drupal\workflow

Code

public function exists($name, array $element, FormStateInterface $form_state) {
  $state_names = [];
  foreach ($form_state
    ->getValue($this->entitiesKey) as $sid => $value) {
    $state_names[] = $value['id'];
  }
  $state_names = array_map('strtolower', $state_names);
  $result = array_unique(array_diff_assoc($state_names, array_unique($state_names)));
  if (in_array($name, $result)) {
    return TRUE;
  }
  return FALSE;
}