You are here

public function MultiFormBuilder::getFormId in Multiple forms 8

Determines the ID of a form.

Parameters

array $form_args: The value is identical to that of self::getForm()'s arguments.

Return value

string The unique string identifying the desired form.

Overrides MultiFormBuilderInterface::getFormId

File

src/MultiFormBuilder.php, line 65
Contains \Drupal\multiform\FormBuilder.

Class

MultiFormBuilder

Namespace

Drupal\multiform

Code

public function getFormId($form_args) {
  $form_id = '';
  foreach ($form_args as $form_arg) {

    // If the $form_arg is the name of a class, instantiate it. Don't allow
    // arbitrary strings to be passed to the class resolver.
    if (is_string($form_arg) && class_exists($form_arg)) {
      $form_arg = $this->classResolver
        ->getInstanceFromDefinition($form_arg);
    }
    if (!is_object($form_arg) || !$form_arg instanceof FormInterface) {
      throw new \InvalidArgumentException(String::format('The multiform argument @form_arg is not a valid form.', array(
        '@form_arg' => $form_arg,
      )));
    }

    // Add the $form_arg as the callback object and determine the form ID.
    if ($form_arg instanceof BaseFormIdInterface) {
      $form_id .= $form_arg
        ->getBaseFormID();
    }
  }
  return $form_id;
}