Drupal 7 and Encrypts redirection problems

Desperately looking for help,
I host several Drupal 7 sites on an Ubuntu 16 under AWS with Apache.
I have domain1.com and new.domain2.com
At the DNS level, I refer to this computer IP for domain1.com and www.domain1.com
I also refer to this IP with "new.domain2.com" (while domain2.com and www.domain2.com point to a different server (new.domain2.com is currently being developed to replace the old one at domin2.com) ,
Domain1.com is of course set up in a subdirectory called "site / domain1.com" and no additional work is required.
In the case of domin2, the directory is called "site / domain2.com", but using the redirect file in "sites / sites.php" I internally change "new.domain2.com" to "domain2.com" using the following line: "$ Sites (& # 39; new.domain2.com & # 39;) = & # 39; domain2.com & # 39 ;;"
So far everything works perfectly. The redirection from new.domain2.com to domain2.com takes place via "sites / sites.php".

Now I wanted to install that we encrypt on both domains.
I used the instruction in: https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04
I used the following lines to create the SSL certificates:
sudo certbot –apache -d domain1.com -d www.domain1.com
and
sudo certbot –apache -d new.domain2.com

The results are:
http://domain1.com is redirected to https://domain1.com and displays the following: "Your connection is not private" NET :: ERR_CERT_COMMON_NAME_INVALID

http://new.domain2.com: good, but says "not sure".
https://new.domin2.com: good and safe (as it should be)

When trying to assess the problem with my limited knowledge, I think that the redirects used by Drupal and "certbot" are contradictory or just don't work well.
What I'm looking for is help debugging or solving this problem, or someone to alert me of a similar problem that others have solved, or at least a good article that explains the redirection system used by Lets Encrypt and Drupal.
thank you in advance

migration – Drupal 8 migrates to paragraphs without parent import

If I have a data source with specific values, can I convert it to a paragraph that is attached to a node in Drupal 8 without having to migrate first to create the paragraphs (and then use a migration_lookup)?

Would I need some kind of process plugin (like importing Json data into node applications) or can this be done immediately with a simple generic subprocess / mapping configuration in the YML file?

Calls – Why can't I remove% 20 from a URL that was evaluated by a context filter (Drupal 8)?

I created a view with context filters with taxonomy terms that consist of two words, so that spaces create% 20 in the URL. I found that the solution was to check the "Convert spaces to hyphens to URL" checkbox, but the URL is still not being removed. Does anyone here know why? I am adding screenshots of the configuration of the view and the URL pattern that I have defined with the pathauto module. Thanks a lot!
Drupal view

Drupal view

Drupal view

Drupal image

Drupal view

drush – Dealing with multiple URLs during Drupal migrations

If you only need to migrate to these 3 IDs, just create 3 different migrations for each URL.

If the IDs are Dinamic, I copy and paste my own solution:

To solve this, I had to create a source plugin that calls a new data analysis plugin for each line with the URL for that line.

Here is the plugin:

/**
*
* @MigrateSource(
*   id = "url_per_row"
* )
*/
class UrlPerRow extends Url {

protected $dataNewParserPlugin;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $prepare_row = parent::prepareRow($row);

    if (!$row->getIdMap() || $row->needsUpdate() || $this->aboveHighwater($row) || $this->rowChanged($row)) {
      $item_info_settings = $row->getSourceProperty('item_info');
      if (!empty($item_info_settings)) {
        $this->getItemData($row, $item_info_settings);
      }
    }

    return $prepare_row;
  }

  protected function getItemData(Row &$row, $settings) {
    $new_url = str_replace($settings('token'), $row->getSourceProperty($settings('token_replace')), $settings('url'));

    $this->getNewDataParserPlugin($new_url, $settings('item_selector'),     $row->getSource());
    $this->dataNewParserPlugin->rewind();
    $xml_data = $this->dataNewParserPlugin->current();
    if (!empty($xml_data)) {
      $fields = $row->getSourceProperty('fields');
      foreach ($fields as $field) {
        if (!empty($field('item_info')) && !empty($xml_data($field('name')))) {
          $row->setSourceProperty($field('name'), $xml_data($field('name')));
        }
      }
    }
  }

  protected function getNewDataParserPlugin($url, $item_selector, $settings) {
    $settings('urls') = ($url);
    $settings('item_selector') = $item_selector;

    $this->dataNewParserPlugin = Drupal::service('plugin.manager.migrate_plus.data_parser')
      ->createInstance($settings('data_parser_plugin'), $settings);

    return $this->dataNewParserPlugin;
  }

}

Then I added some information to the .yml migration definition:

source:
  plugin: url_per_row
  data_fetcher_plugin: http
  headers:
    Accept: application/xml
  data_parser_plugin: simple_xml
  urls: https://myws.com
  item_selector: /ResultWeb/data
  item_info:
    url: https://myws.com/(id)
    token: '(id)'
    token_replace: id
    item_selector: /ResultWeb/data

Note that the id of token_replace is a field with names I would, You can use another field.

I also have one for each field that requires information to be retrieved from the specified URL item_info: true Element.

-
  name: myfield
  label: 'My Field'
  selector: fields/field/my
  item_info: true

Theming – Error when setting up Drupal 8.1.1

Notice: Trying to access array offset on value of type null in DrupalComponentAnnotationDoctrineDocParser->Identifier() (line 969 of corelibDrupalComponentAnnotationDoctrineDocParser.php).
DrupalComponentAnnotationDoctrineDocParser->Identifier() (Line: 664)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Defines a form element plugin annotation object.
 *
 * See DrupalCoreRenderElementFormElementInterface for more information
 * about form element plugins.
 *
 * Plugin Namespace: Element
 *
 * For a working example, see DrupalCoreRenderElementTextfield.
 *
 * @see DrupalCoreRenderElementInfoManager
 * @see DrupalCoreRenderElementFormElementInterface
 * @see DrupalCoreRenderElementFormElement
 * @see DrupalCoreRenderAnnotationRenderElement
 * @see plugin_api
 *
 * @ingroup theme_render
 *
 * @Annotation
 */', 'class @DrupalCoreRenderAnnotationFormElement') (Line: 495)
DrupalComponentAnnotationDoctrineDocParser->collectAnnotationMetadata('DrupalCoreRenderAnnotationFormElement') (Line: 720)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Provides a datelist element.
 *
 * @FormElement("datelist")
 */', 'class DrupalCoreDatetimeElementDatelist') (Line: 101)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotation(Object, 'DrupalCoreRenderAnnotationRenderElement') (Line: 145)
DrupalComponentAnnotationPluginDiscoveryAnnotatedClassDiscovery->getDefinitions() (Line: 86)
DrupalComponentPluginDiscoveryDerivativeDiscoveryDecorator->getDefinitions() (Line: 284)
DrupalCorePluginDefaultPluginManager->findDefinitions() (Line: 175)
DrupalCorePluginDefaultPluginManager->getDefinitions() (Line: 110)
DrupalCoreRenderElementInfoManager->buildInfo('seven') (Line: 77)
DrupalCoreRenderElementInfoManager->getInfo('form') (Line: 812)
DrupalCoreFormFormBuilder->prepareForm('install_select_language_form', Array, Object) (Line: 278)
DrupalCoreFormFormBuilder->buildForm('DrupalCoreInstallerFormSelectLanguageForm', Object) (Line: 955)
install_get_form('DrupalCoreInstallerFormSelectLanguageForm', Array) (Line: 1375)
install_select_language(Array) (Line: 702)
install_run_task(Array, Array) (Line: 577)
install_run_tasks(Array, NULL) (Line: 117)
install_drupal(Object) (Line: 44)
Notice: Trying to access array offset on value of type null in DrupalComponentAnnotationDoctrineDocParser->Identifier() (line 969 of corelibDrupalComponentAnnotationDoctrineDocParser.php).
DrupalComponentAnnotationDoctrineDocParser->Identifier() (Line: 664)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Defines a render element plugin annotation object.
 *
 * See DrupalCoreRenderElementElementInterface for more information
 * about render element plugins.
 *
 * Plugin Namespace: Element
 *
 * For a working example, see DrupalCoreRenderElementLink.
 *
 * @see DrupalCoreRenderElementInfoManager
 * @see DrupalCoreRenderElementElementInterface
 * @see DrupalCoreRenderElementRenderElement
 * @see DrupalCoreRenderAnnotationFormElement
 * @see plugin_api
 *
 * @ingroup theme_render
 *
 * @Annotation
 */', 'class @DrupalCoreRenderAnnotationRenderElement') (Line: 495)
DrupalComponentAnnotationDoctrineDocParser->collectAnnotationMetadata('DrupalCoreRenderAnnotationRenderElement') (Line: 720)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Provides a wrapper element to group one or more buttons in a form.
 *
 * Use of a single Actions element with an array key of 'actions' to group the
 * primary submit buttons on a form helps to ensure proper styling in themes,
 * and enables other modules to properly alter a form's actions.
 *
 * Usage example:
 * @code
 * $form('actions') = array('#type' => 'actions');
 * $form('actions')('submit') = array(
 *   '#type' => 'submit',
 *   '#value' => $this->t('Save'),
 * );
 * @endcode
 *
 * @RenderElement("actions")
 */', 'class DrupalCoreRenderElementActions') (Line: 101)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotation(Object, 'DrupalCoreRenderAnnotationRenderElement') (Line: 145)
DrupalComponentAnnotationPluginDiscoveryAnnotatedClassDiscovery->getDefinitions() (Line: 86)
DrupalComponentPluginDiscoveryDerivativeDiscoveryDecorator->getDefinitions() (Line: 284)
DrupalCorePluginDefaultPluginManager->findDefinitions() (Line: 175)
DrupalCorePluginDefaultPluginManager->getDefinitions() (Line: 110)
DrupalCoreRenderElementInfoManager->buildInfo('seven') (Line: 77)
DrupalCoreRenderElementInfoManager->getInfo('form') (Line: 812)
DrupalCoreFormFormBuilder->prepareForm('install_select_language_form', Array, Object) (Line: 278)
DrupalCoreFormFormBuilder->buildForm('DrupalCoreInstallerFormSelectLanguageForm', Object) (Line: 955)
install_get_form('DrupalCoreInstallerFormSelectLanguageForm', Array) (Line: 1375)
install_select_language(Array) (Line: 702)
install_run_task(Array, Array) (Line: 577)
install_run_tasks(Array, NULL) (Line: 117)
install_drupal(Object) (Line: 44)
Notice: Trying to access array offset on value of type null in DrupalComponentAnnotationDoctrineDocParser->Identifier() (line 969 of corelibDrupalComponentAnnotationDoctrineDocParser.php).
DrupalComponentAnnotationDoctrineDocParser->Identifier() (Line: 664)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Defines a config entity type annotation object.
 *
 * The annotation properties of entity types are found on
 * DrupalCoreConfigEntityConfigEntityType and are accessed using
 * get/set methods defined in DrupalCoreEntityEntityTypeInterface.
 *
 * @ingroup entity_api
 *
 * @Annotation
 */', 'class @DrupalCoreEntityAnnotationConfigEntityType') (Line: 495)
DrupalComponentAnnotationDoctrineDocParser->collectAnnotationMetadata('DrupalCoreEntityAnnotationConfigEntityType') (Line: 720)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Defines the Date Format configuration entity class.
 *
 * @ConfigEntityType(
 *   id = "date_format",
 *   label = @Translation("Date format"),
 *   handlers = {
 *     "access" = "DrupalsystemDateFormatAccessControlHandler",
 *   },
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label"
 *   },
 *   admin_permission = "administer site configuration",
 *   list_cache_tags = { "rendered" },
 *   config_export = {
 *     "id",
 *     "label",
 *     "locked",
 *     "pattern",
 *   }
 * )
 */', 'class DrupalCoreDatetimeEntityDateFormat') (Line: 101)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotation(Object, 'DrupalCoreEntityAnnotationEntityType') (Line: 145)
DrupalComponentAnnotationPluginDiscoveryAnnotatedClassDiscovery->getDefinitions() (Line: 123)
DrupalCoreEntityEntityTypeManager->findDefinitions() (Line: 175)
DrupalCorePluginDefaultPluginManager->getDefinitions() (Line: 22)
DrupalCorePluginDefaultPluginManager->getDefinition('date_format', ) (Line: 143)
DrupalCoreEntityEntityTypeManager->getDefinition('date_format') (Line: 269)
DrupalCoreEntityEntityTypeManager->getHandler('date_format', 'storage') (Line: 208)
DrupalCoreEntityEntityTypeManager->getStorage('date_format') (Line: 93)
DrupalCoreDatetimeDateFormatter->__construct(Object, Object, Object, Object, Object)
ReflectionClass->newInstanceArgs(Array) (Line: 1176)
SymfonyComponentDependencyInjectionContainerBuilder->createService(Object, Array, 1, 'date.formatter') (Line: 634)
SymfonyComponentDependencyInjectionContainerBuilder->doGet('date.formatter', 1) (Line: 588)
SymfonyComponentDependencyInjectionContainerBuilder->get('date.formatter') (Line: 87)
DrupalCoreTempStoreElementBreakLockLink::create(Object, Array, 'break_lock_link', Array) (Line: 21)
DrupalCorePluginFactoryContainerFactory->createInstance('break_lock_link', Array) (Line: 83)
DrupalComponentPluginPluginManagerBase->createInstance('break_lock_link', Array) (Line: 141)
DrupalCoreRenderElementInfoManager->createInstance('break_lock_link') (Line: 111)
DrupalCoreRenderElementInfoManager->buildInfo('seven') (Line: 77)
DrupalCoreRenderElementInfoManager->getInfo('form') (Line: 812)
DrupalCoreFormFormBuilder->prepareForm('install_select_language_form', Array, Object) (Line: 278)
DrupalCoreFormFormBuilder->buildForm('DrupalCoreInstallerFormSelectLanguageForm', Object) (Line: 955)
install_get_form('DrupalCoreInstallerFormSelectLanguageForm', Array) (Line: 1375)
install_select_language(Array) (Line: 702)
install_run_task(Array, Array) (Line: 577)
install_run_tasks(Array, NULL) (Line: 117)
install_drupal(Object) (Line: 44)
Notice: Trying to access array offset on value of type null in DrupalComponentAnnotationDoctrineDocParser->Identifier() (line 969 of corelibDrupalComponentAnnotationDoctrineDocParser.php).
DrupalComponentAnnotationDoctrineDocParser->Identifier() (Line: 664)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Defines a translatable annotation object.
 *
 * Some metadata within an annotation needs to be translatable. This class
 * supports that need by allowing both the translatable string and, if
 * specified, a context for that string. The string (with optional context)
 * is passed into t().
 *
 * @ingroup plugin_translatable
 *
 * @Annotation
 */', 'class @DrupalCoreAnnotationTranslation') (Line: 495)
DrupalComponentAnnotationDoctrineDocParser->collectAnnotationMetadata('DrupalCoreAnnotationTranslation') (Line: 720)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 1009)
DrupalComponentAnnotationDoctrineDocParser->PlainValue() (Line: 1061)
DrupalComponentAnnotationDoctrineDocParser->FieldAssignment() (Line: 991)
DrupalComponentAnnotationDoctrineDocParser->Value() (Line: 860)
DrupalComponentAnnotationDoctrineDocParser->Values() (Line: 835)
DrupalComponentAnnotationDoctrineDocParser->MethodCall() (Line: 746)
DrupalComponentAnnotationDoctrineDocParser->Annotation() (Line: 640)
DrupalComponentAnnotationDoctrineDocParser->Annotations() (Line: 338)
DrupalComponentAnnotationDoctrineDocParser->parse('/**
 * Defines the Date Format configuration entity class.
 *
 * @ConfigEntityType(
 *   id = "date_format",
 *   label = @Translation("Date format"),
 *   handlers = {
 *     "access" = "DrupalsystemDateFormatAccessControlHandler",
 *   },
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label"
 *   },
 *   admin_permission = "administer site configuration",
 *   list_cache_tags = { "rendered" },
 *   config_export = {
 *     "id",
 *     "label",
 *     "locked",
 *     "pattern",
 *   }
 * )
 */', 'class DrupalCoreDatetimeEntityDateFormat') (Line: 101)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)
DrupalComponentAnnotationDoctrineSimpleAnnotationReader->getClassAnnotation(Object, 'DrupalCoreEntityAnnotationEntityType') (Line: 145)
DrupalComponentAnnotationPluginDiscoveryAnnotatedClassDiscovery->getDefinitions() (Line: 123)
DrupalCoreEntityEntityTypeManager->findDefinitions() (Line: 175)
DrupalCorePluginDefaultPluginManager->getDefinitions() (Line: 22)
DrupalCorePluginDefaultPluginManager->getDefinition('date_format', ) (Line: 143)
DrupalCoreEntityEntityTypeManager->getDefinition('date_format') (Line: 269)
DrupalCoreEntityEntityTypeManager->getHandler('date_format', 'storage') (Line: 208)
DrupalCoreEntityEntityTypeManager->getStorage('date_format') (Line: 93)
DrupalCoreDatetimeDateFormatter->__construct(Object, Object, Object, Object, Object)
ReflectionClass->newInstanceArgs(Array) (Line: 1176)
SymfonyComponentDependencyInjectionContainerBuilder->createService(Object, Array, 1, 'date.formatter') (Line: 634)
SymfonyComponentDependencyInjectionContainerBuilder->doGet('date.formatter', 1) (Line: 588)
SymfonyComponentDependencyInjectionContainerBuilder->get('date.formatter') (Line: 87)
DrupalCoreTempStoreElementBreakLockLink::create(Object, Array, 'break_lock_link', Array) (Line: 21)
DrupalCorePluginFactoryContainerFactory->createInstance('break_lock_link', Array) (Line: 83)
DrupalComponentPluginPluginManagerBase->createInstance('break_lock_link', Array) (Line: 141)
DrupalCoreRenderElementInfoManager->createInstance('break_lock_link') (Line: 111)
DrupalCoreRenderElementInfoManager->buildInfo('seven') (Line: 77)
DrupalCoreRenderElementInfoManager->getInfo('form') (Line: 812)
DrupalCoreFormFormBuilder->prepareForm('install_select_language_form', Array, Object) (Line: 278)
DrupalCoreFormFormBuilder->buildForm('DrupalCoreInstallerFormSelectLanguageForm', Object) (Line: 955)
install_get_form('DrupalCoreInstallerFormSelectLanguageForm', Array) (Line: 1375)
install_select_language(Array) (Line: 702)
install_run_task(Array, Array) (Line: 577)
install_run_tasks(Array, NULL) (Line: 117)

Receive an error message
install_drupal (object) (line: 44)

Hooks – (Drupal 7) How can I report a mistake to a visitor?

I'm using a custom submit handler for a web form that forwards key form data to another API. This part works, but occasionally there may be random network errors that prevent a successful transmission, e.g. B. if the REST endpoint was just not available (or whatever).

In these cases, I don't want the user to think that their form has been submitted successfully if it hasn't. How can I overwrite the confirmation page with a custom error page? I tried drupal_set_message(), but it doesn't appear anywhere on the confirmation page that I could see.

Ideally, I can also get back the event ID generated by watchdog Logging so that when the user contacts us by phone or email when the error occurs, they can provide additional information that can help us debug.

In summary, a failed submission in a perfect world would result in the following:

  1. The form submission ($ form_state) is logged in Watchdog or another protocol
  2. Watchdog returns the associated event ID
  3. The user is presented with a custom error page with the event ID as the error code to make debugging easier.

I can hack something along with it die() and a hash of the form data as an error code, but is there a better, correct Drupal way?

Relevant code so far:

 try {
    $apiResponse = drupal_http_request($apiEndPoint, (
      'headers' => ('Content-Type' => 'application/json'),
      'method' => 'POST',
      'data' => drupal_json_encode($formData),
      'timeout' => 5 // Timeout in seconds.
    ));

    // I'm not okay :(
    if ($apiResponse->code != "200") {
      throw new Exception ($apiResponse->data, $apiResponse->code);
    }
  } catch (Throwable $e) {
    watchdog('tfm_custom_form_handlers', "A custom form handler failed: (@code) @message.", (
      '@code' => $e->getCode(),
      '@message' => $e->getMessage(),
    ), WATCHDOG_ERROR);
  }

Thanks for your help!

How do I fix PrivateTempStore for session data in Drupal 8?

The Drupal 8 replacement for $_SESSION is not PrivateTempStore, but the session object in the request:

Drupal 7:

function mymodule_session_counter_increment() {
  if (!isset($_SESSION('mymodule_count'))) {
    $_SESSION('mymodule_count') = 0;
  }

  return $_SESSION('mymodule_count')++;
}

Drupal 8:

class MymoduleSessionCounter {
  function increment(Request $request) {
    $session = $request->getSession();
    $value = $session->get('mymodule_count', 0);
    $session->set('mymodule_count', $value + 1);

    return $value;
  }
}

See change record: https://www.drupal.org/node/2380327

For more information, see this topic: How do I save the values ​​submitted in a form in the session?

forms – Drupal 8: Generate options based on Ajax callback

In Drupal 8 I want to generate options of the second selection box based on Ajax calls of the first selection box. The result generates a third new selection field, but I don't have to generate a new one. I want to replace the options in the second selection box. Please see my codes below:

public function buildForm(array $form, FormStateInterface $form_state) {
$form('example_select') = (
  '#type' => 'select',
  '#title' => $this->t('Select element'),
  'wrapper' => 'first',
  '#options' => (
    '1' => $this->t('One'),
    '2' => $this->t('Two'),
    '3' => $this->t('Three'),
    '4' => $this->t('From New York to Ger-ma-ny!'),
  ),
  '#ajax' => (
    'callback' => '::myAjaxCallback', 
    'disable-refocus' => FALSE, 
    'event' => 'change',
    'wrapper' => 'edit-output', 
    'progress' => (
      'type' => 'throbber',
      'message' => $this->t('Verifying entry...'),
    ),
  )
);


$form('example_select2') = (
  '#type' => 'select',
  '#title' => $this->t('Select element'),
  '#prefix' => '
', '#suffix' => '
', '#options' => ( ), '#ajax' => ( 'callback' => '::myAjaxCallback2', 'disable-refocus' => FALSE, 'event' => 'change', 'wrapper' => 'edit-output', 'progress' => ( 'type' => 'throbber', 'message' => $this->t('Verifying entry...'), ), ) ); return $form; } public function myAjaxCallback(array &$form, FormStateInterface $form_state) { if ($selectedValue = $form_state->getValue('example_select')) { $arr = array('1' => 'Nice way', '2' => 'Good way'); $form('example_select2')('#options') = $arr; } return $form('example_select2'); }