You are here

public function PluginFormFactory::createInstance in Feeds 8.3

Creates a form instance for the plugin.

Parameters

\Drupal\feeds\Plugin\Type\FeedsPluginInterface $plugin: The Feeds plugin.

string $operation: The type of form to create. See ::hasForm above for possible types.

Return value

\Drupal\Core\Plugin\PluginFormInterface A form for the plugin.

File

src/Plugin/PluginFormFactory.php, line 72

Class

PluginFormFactory
Provides form discovery capabilities for plugins.

Namespace

Drupal\feeds\Plugin

Code

public function createInstance(FeedsPluginInterface $plugin, $operation) {
  $definition = $plugin
    ->getPluginDefinition();

  // If the form specified is the plugin itself, use it directly.
  if (get_class($plugin) === ltrim($definition['form'][$operation], '\\')) {
    $form_object = $plugin;
  }
  else {
    $form_object = $this->classResolver
      ->getInstanceFromDefinition($definition['form'][$operation]);
  }

  // Ensure the resulting object is a plugin form.
  if (!$form_object instanceof PluginFormInterface) {
    throw new \LogicException($plugin
      ->getPluginId(), sprintf('The "%s" plugin did not specify a valid "%s" form class, must implement \\Drupal\\Core\\Plugin\\PluginFormInterface', $plugin
      ->getPluginId(), $operation));
  }
  if ($form_object instanceof PluginAwareInterface) {
    $form_object
      ->setPlugin($plugin);
  }
  return $form_object;
}