PluginSubFormHelpers.php in Pardot Integration 2.x
Namespace
Drupal\pardotFile
src/PluginSubFormHelpers.phpView source
<?php
namespace Drupal\pardot;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
use Drupal\Core\Plugin\PluginFormInterface;
/**
* Provides an interface for defining Pardot Form Map entities.
*/
class PluginSubFormHelpers {
/**
* Help Submit plugin forms.
*
* @param \Drupal\Core\Plugin\PluginFormInterface $plugin
* The plugin instance.
* @param array $form
* The form for creating the subform.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state to use for creating the subform state.
* @param array $parents
* The array parent. Where to get the plugin instance form.
*
* @return array|\Drupal\Core\Plugin\PluginFormInterface
* Either return the plugin or an empty array.
*/
public static function pluginSubmit($plugin, array &$form, FormStateInterface $form_state, array $parents) {
if ($plugin instanceof PluginFormInterface) {
if (!($plugin_form = NestedArray::getValue($form, $parents))) {
$plugin_form = [];
}
$plugin_form_state = SubformState::createForSubform($plugin_form, $form, $form_state);
$plugin
->submitConfigurationForm($plugin_form, $plugin_form_state);
return $plugin;
}
else {
return [];
}
}
/**
* Help Submit plugin forms.
*
* @param \Drupal\Core\Plugin\PluginFormInterface $plugin
* The plugin instance.
* @param array $form
* The form for creating the subform.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state to use for creating the subform state.
* @param array $parents
* The array parent. Where to get the plugin instance form.
*
* @return array|\Drupal\Core\Plugin\PluginFormInterface
* Either return the plugin or an empty array.
*/
public static function buildPluginForm($plugin, array $form, FormStateInterface $form_state, array $parents) {
if ($plugin instanceof PluginFormInterface) {
if (!($plugin_form = NestedArray::getValue($form, $parents))) {
$plugin_form = [];
}
$plugin_form_state = SubformState::createForSubform($plugin_form, $form, $form_state);
$plugin_form = $plugin
->buildConfigurationForm($plugin_form, $plugin_form_state);
$plugin_form['#tree'] = TRUE;
return $plugin_form;
}
else {
return [];
}
}
}
Classes
Name | Description |
---|---|
PluginSubFormHelpers | Provides an interface for defining Pardot Form Map entities. |