You are here

public function FormComponentTypeBase::getComponent in Flexiform 8

Get a component object.

Parameters

string $name: The name of the component.

array $options: The options for the component.

Return value

\Drupal\flexiform\FormComponent\FormComponentInterface The form component.

Overrides FormComponentTypeInterface::getComponent

2 calls to FormComponentTypeBase::getComponent()
ExtraFieldComponentType::getComponent in src/Plugin/FormComponentType/ExtraFieldComponentType.php
Get a component object.
FieldWidgetComponentType::getComponent in src/Plugin/FormComponentType/FieldWidgetComponentType.php
Get a component object.
2 methods override FormComponentTypeBase::getComponent()
ExtraFieldComponentType::getComponent in src/Plugin/FormComponentType/ExtraFieldComponentType.php
Get a component object.
FieldWidgetComponentType::getComponent in src/Plugin/FormComponentType/FieldWidgetComponentType.php
Get a component object.

File

src/FormComponent/FormComponentTypeBase.php, line 41

Class

FormComponentTypeBase
Base class for form component types.

Namespace

Drupal\flexiform\FormComponent

Code

public function getComponent($name, array $options = []) {
  $class = $this
    ->getPluginDefinition()['component_class'];
  if (!class_exists($class)) {
    throw new \Exception("No Component class for Form Component Type " . $this
      ->getPluginId());
  }
  if (empty($options)) {
    $options = [];
  }
  if (is_subclass_of($class, 'Drupal\\flexiform\\FormComponent\\ContainerFactoryFormComponentInterface')) {
    return $class::create(\Drupal::getContainer(), $name, $options, $this
      ->getFormDisplay());
  }
  return new $class($name, $options, $this
    ->getFormDisplay());
}