YamlFormEntityThirdPartySettingsForm.php in YAML Form 8
File
src/YamlFormEntityThirdPartySettingsForm.php
View source
<?php
namespace Drupal\yamlform;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class YamlFormEntityThirdPartySettingsForm extends EntityForm {
protected $settingsManager;
public function __construct(YamlFormThirdPartySettingsManagerInterface $settings_manager) {
$this->settingsManager = $settings_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('yamlform.third_party_settings_manager'));
}
public function form(array $form, FormStateInterface $form_state) {
$form = $this->settingsManager
->buildForm($form, $form_state);
$form_state
->set('yamlform', $this
->getEntity());
return parent::form($form, $form_state);
}
protected function actionsElement(array $form, FormStateInterface $form_state) {
$element = parent::actionsElement($form, $form_state);
unset($element['delete']);
return $element;
}
public function save(array $form, FormStateInterface $form_state) {
$yamlform = $this
->getEntity();
$third_party_settings = $form_state
->getValue('third_party_settings');
foreach ($third_party_settings as $module => $third_party_setting) {
foreach ($third_party_setting as $key => $value) {
$yamlform
->setThirdPartySetting($module, $key, $value);
}
}
$yamlform
->save();
$this
->logger('yamlform')
->notice('Form settings @label saved.', [
'@label' => $yamlform
->label(),
]);
drupal_set_message($this
->t('Form settings %label saved.', [
'%label' => $yamlform
->label(),
]));
}
}