PathFileEntitySettingsForm.php in Path File 8
File
src/Form/PathFileEntitySettingsForm.php
View source
<?php
namespace Drupal\path_file\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PathFileEntitySettingsForm extends ConfigFormBase {
protected $entityDefinitionUpdateManager;
public function __construct(ConfigFactoryInterface $config_factory, EntityDefinitionUpdateManagerInterface $entityDefinitionUpdateManager) {
$this
->setConfigFactory($config_factory);
$this->entityDefinitionUpdateManager = $entityDefinitionUpdateManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity.definition_update_manager'));
}
public function getFormId() {
return 'PathFileEntity_settings';
}
protected function getEditableConfigNames() {
return [
'path_file.settings',
];
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$allowed_extensions = $form_state
->getValue('allowed_extensions');
$config = $this
->config('path_file.settings');
$config
->set('allowed_extensions', $allowed_extensions)
->save();
$field = $this->entityDefinitionUpdateManager
->getFieldStorageDefinition("fid", "path_file_entity");
$this->entityDefinitionUpdateManager
->updateFieldStorageDefinition($field);
parent::submitForm($form, $form_state);
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['PathFileEntity_settings']['#markup'] = 'Settings form for Path file entity entities. Manage field settings here.';
$config = $this
->config('path_file.settings');
$allowed_extensions = $config
->get('allowed_extensions');
$form['allowed_extensions'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Allowed File Extensions'),
'#default_value' => $allowed_extensions,
);
return parent::buildForm($form, $form_state);
}
}