public function FlowForm::form in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::form()
- 2.0.x src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ FlowForm.php, line 187
Class
- FlowForm
- Form handler for the Flow add and edit forms.
Namespace
Drupal\cms_content_sync\FormCode
public function form(array $form, FormStateInterface $form_state) {
$type = $this
->getCurrentFormType();
// Add form library for some custom styling.
$form['#attached']['library'][] = 'cms_content_sync/flow-form';
if (!$type) {
return $this
->selectTypeForm($form, $form_state);
}
// Before a flow can be created, at least one pool must exist.
// Get all pool entities.
$pool_entities = Pool::getAll();
if (empty($pool_entities)) {
global $base_url;
$path = Url::fromRoute('cms_content_sync.cms_content_sync_pool.pool_required')
->toString();
$response = new RedirectResponse($base_url . $path);
$response
->send();
}
$form = parent::form($form, $form_state);
$form['#tree'] = true;
if ($this
->shouldOpenAll($form_state)) {
$form['open_all'] = [
'#type' => 'hidden',
'#value' => '1',
];
}
/**
* @var \Drupal\cms_content_sync\Entity\Flow $flow
*/
$flow = $this->entity;
$form['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
'#maxlength' => 255,
'#attributes' => [
'autofocus' => 'autofocus',
],
'#default_value' => $flow
->label(),
'#description' => $this
->t('An administrative name describing the workflow intended to be achieved with this synchronization.'),
'#required' => true,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $flow
->id(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'source' => [
'name',
],
],
'#disabled' => !$flow
->isNew(),
];
$config_machine_name = $flow
->id();
if (!isset($config_machine_name)) {
$config_machine_name = '<machine_name_of_the_configuration>';
}
$flow_id = $flow
->id();
if (isset($flow_id)) {
$flow_id = 'cms_content_sync.flow.' . $flow_id;
$non_overridden_config = $this->configFactory
->get($flow_id)
->getRawData();
$non_overridden_flow_status = isset($non_overridden_config['status']) ? $non_overridden_config['status'] : null;
}
$flow_status_description = '';
$active_flow_status = $this->configFactory
->get($flow_id)
->get('status');
if (isset($non_overridden_flow_status, $active_flow_status)) {
if ($active_flow_status != $non_overridden_flow_status) {
$flow_status_description = '<br><b>This value is overridden within the settings.php file.</b>';
}
}
$form['status'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Active'),
'#default_value' => isset($non_overridden_flow_status) ? $non_overridden_flow_status : true,
'#description' => $this
->t('If the flow is not active, none of the below configured behaviors will take effect. This configuration could be overwritten within your environment specific settings.php file:<br> <i>@status_config</i>.' . $flow_status_description . '', [
'@status_config' => '$config["cms_content_sync.flow.' . $config_machine_name . '"]["status"] = FALSE;',
]),
];
$form['type'] = [
'#title' => $this
->t('Type'),
'#markup' => '<br>' . $this
->t('Right now the this Flow is set to @type. <strong>If you want to change it, first save all changes you made as otherwise they will be lost!</strong> Then click here: ', [
'@type' => Flow::TYPE_BOTH === $type ? $this
->t('Push and Pull') : (Flow::TYPE_PULL === $type ? $this
->t('Pull') : $this
->t('Push')),
]) . '<a href="?type=">' . $this
->t('Change') . '</a><br><br>',
];
$entity_types = $this->bundleInfoService
->getAllBundleInfo();
ksort($entity_types);
// Remove the Content Sync Entity Status entity type form the array.
unset($entity_types['cms_content_sync_entity_status']);
$entity_type_list = [
'#type' => 'vertical_tabs',
'#default_tab' => 'edit-node',
'#tree' => true,
];
$form['entity_type_list'] = $entity_type_list;
foreach ($entity_types as $type_key => $entity_type) {
$this
->renderEntityType($form, $form_state, $type_key);
}
$this
->disableOverridenConfigs($form);
return $form;
}