EntityUpdateTestSettings.php in Entity Update 8
File
modules/entity_update_tests/src/Form/EntityUpdateTestSettings.php
View source
<?php
namespace Drupal\entity_update_tests\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_update_tests\Entity\EntityUpdateTestsContentEntity;
use Drupal\entity_update_tests\Entity\EntityUpdateTestsContentEntity02;
use Drupal\entity_update_tests\EntityUpdateTestHelper;
class EntityUpdateTestSettings extends FormBase {
public function getFormId() {
return 'entity_update_tests';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$link_help = '/admin/help/entity_update';
$form['messages']['about'] = [
'#type' => 'markup',
'#markup' => "<a href='{$link_help}'>Help page</a>.",
'#prefix' => '<div>',
'#suffix' => '</div>',
];
$fields = self::getConfigurableFields('install');
foreach ($fields as $field_key => $field_name) {
$form['fields'][$field_key] = [
'#type' => 'checkbox',
'#title' => "Field : {$field_name}",
'#default_value' => EntityUpdateTestHelper::fieldStatus($field_key),
];
}
$fields = self::getConfigurableFields('type');
foreach ($fields as $field_key => $field_name) {
$form['fields'][$field_key] = [
'#type' => 'select',
'#options' => [
'string' => 'String',
'integer' => 'Integer',
],
'#title' => "Field : {$field_name}",
'#default_value' => EntityUpdateTestHelper::fieldStatus($field_key),
];
}
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$fields = self::getConfigurableFields();
foreach ($fields as $field_key => $field_name) {
$value = $form_state
->getValue($field_key);
drupal_set_message("{$field_name} : ({$value}) " . ($value ? "TRUE" : "FALSE"));
EntityUpdateTestHelper::fieldEnable($field_key, $value);
}
drupal_set_message($this
->t("Test entity configuration success"));
}
private static function getConfigurableFields($mode = NULL) {
$fields = EntityUpdateTestsContentEntity::getConfigurableFields($mode);
$fields += EntityUpdateTestsContentEntity02::getConfigurableFields($mode);
return $fields;
}
}