Skip to content
Snippets Groups Projects

Issue #3450055: Remove dedicated environments

Merged Christian Foidl requested to merge 3450055-remove-dedicated-environments into 1.0.x
18 files
+ 60
672
Compare changes
  • Side-by-side
  • Inline
Files
18
<?php
namespace Drupal\nextjs\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\Select;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
/**
* Provides a select form element that displays available nextjs environments.
*
* Properties:
* - #empty_option: The label that will be displayed to denote no selection.
* - #empty_value: The value of the option that is used to denote no selection.
* - #env_description: A boolean value that determines if information about
* environment is added to the element's description.
*
* @FormElement("nextjs_environment_select")
*/
class NextjsEnvironmentSelect extends Select {
/**
* {@inheritdoc}
*/
public function getInfo() {
$info = parent::getInfo();
$class = get_class($this);
// Add a process function.
array_unshift($info['#process'], [$class, 'processNextjsEnvironmentSelect']);
// Add a property for Next.js environment description.
$info['#env_description'] = TRUE;
// Add the 'empty' option.
$info['#empty_option'] = $this->t('- Select a Next.js environment -');
return $info;
}
/**
* Processes a Next.js environment select list form element.
*
* @param array $element
* The form element to process.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $complete_form
* The complete form structure.
*
* @return array
* The processed element.
*/
public static function processNextjsEnvironmentSelect(array &$element, FormStateInterface $form_state, array &$complete_form) {
// Get the list of available environments and define the options.
$options = \Drupal::service('nextjs_environment.repository')->getEnvironmentNamesAsOptions();
$element['#options'] = $options;
// Prefix the default description with information about
// Next.js environments, unless disabled.
if ($element['#env_description']) {
$originalDescription = (isset($element['#description'])) ? $element['#description'] : '';
// @todo this causes escaping.
$envDescription = new TranslatableMarkup('Choose an available environment. If the desired environment is not listed, <a href=":link">create a new environment</a>.', [
':link' => Url::fromRoute('entity.nextjs_environment.add_form')->toString(),
]);
$element['#description'] = $envDescription . ' ' . $originalDescription;
}
return $element;
}
}
Loading