Drupal StackExchange

How to set a validation error via ajax?

6 days 11 hours ago

I am using the formapi to create a form. On one of my fields I have an #ajax call. When the field is changed I call the function. I recreate the form and then replace the whole form on the page. This works fine.

When creating the form I have some logic that sets the form state to see if a field has a value. If it has a value then I show some more fields. If the value is not set then I don't show the fields. I am showing the fields by setting the #access on the field.

I need to add some validation on the form when the ajax call is triggered. I have tried adding the validation using form_set_error() in the function that creates the form and in the ajax callback but the error is not displayed on the screen.

Am I going about this the wrong way completely? How can I get the form error to display?

user13134

Migration Plus entity_lookup fails

6 days 11 hours ago

Drupal version: 8.7.1. Used modules:

  • Migrate
  • Migrate Plus
  • Migrate Tools
  • Migrate Spreadsheet

I'm trying to generate a taxonomy term if this does not already exist. the migration file:

... source: plugin: spreadsheet columns: ... - 'Functie' ... process: ... field_function: plugin: entity_generate source: 'Functie' value_key: name ignore_case: true bundle: function entity_type: taxonomy_term ...

The taxonomy bundle name is function and the column in the spreadsheet containing the values is 'Functie'. However, I'm getting the following error:

[error] Error: Call to a member function getConfig() on null in Drupal\migrate_plus\Plugin\migrate\process\EntityLookup->determineLookupProperties() (line 217 of /var/www/html/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php)

/var/www/html/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php(182): Drupal\migrate_plus\Plugin\migrate\process\EntityLookup->determineLookupProperties('field_function')

/var/www/html/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityGenerate.php(116): Drupal\migrate_plus\Plugin\migrate\process\EntityLookup->transform('Medewerker', Object(Drupal\migrate_tools\MigrateExecutable), Object(Drupal\migrate\Row), 'field_function')

/var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(394): Drupal\migrate_plus\Plugin\migrate\process\EntityGenerate->transform('Medewerker', Object(Drupal\migrate_tools\MigrateExecutable), Object(Drupal\migrate\Row), 'field_function')

/var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(203): Drupal\migrate\MigrateExecutable->processRow(Object(Drupal\migrate\Row))

/var/www/html/vendor/drush/drush/includes/drush.inc(223): Drupal\migrate\MigrateExecutable->import()

/var/www/html/vendor/drush/drush/includes/drush.inc(214): drush_call_user_func_array(Array, Array)

/var/www/html/web/modules/contrib/migrate_tools/src/Commands/MigrateToolsCommands.php(766): drush_op(Array)

[internal function]: Drupal\migrate_tools\Commands\MigrateToolsCommands->executeMigration(Object(Drupal\migrate\Plugin\Migration), 'profiles', Array)

/var/www/html/web/modules/contrib/migrate_tools/src/Commands/MigrateToolsCommands.php(321): array_walk(Array, Array, Array)

[internal function]: Drupal\migrate_tools\Commands\MigrateToolsCommands->import('profiles', Array)

/var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)

/var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))

/var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))

/var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))

/var/www/html/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

/var/www/html/vendor/symfony/console/Application.php(978): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

/var/www/html/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

/var/www/html/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

/var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

/var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(49): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))

/var/www/html/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)

/var/www/html/vendor/drush/drush/includes/preflight.inc(18): require('/var/www/html/v...')

phar:///usr/local/bin/drush/bin/drush.php(141): drush_main() /usr/local/bin/drush(10): require('phar:///usr/loc...')

If anyone could point out what's going wrong, by all means, enlighten me because I have no clue what's going on, the configuration seems right to me.

Geordi Feijens

Erroneous .tar.gz created by drush archive:dump. The archive cannot be restored with drush archive:restore

6 days 12 hours ago

I use Debian 11, PHP 8.1.28, drupal/core-recommended:10.2.6 and drush/drush:12.5.2.

When I run drush archive:dump no error is reported. But when I want to restore the archive with drush archive:restore I receive the following error that seems to be related to the contents of the .tar.gz file:

[warning] PharData::extractTo(/home/drupal/drush-backups/drushTpUnvd/drupal_site/code/web/.gitignore): Failed to open stream: No such file or directory ArchiveRestoreCommands.php:258 In ArchiveRestoreCommands.php line 258: Extraction from phar "/home/drupal/drush-backups/drupal_site.tar.gz" failed: Cannot extract "code/web/.gitignore", could not open for writing "/home/drupal/drush-backups/drushTpUnvd/drupal_site/code/web/.gitignore"

The command "tar -xvzf drupal_site.tar.gz" reports errors similar with the following at the standard error:

tar: code/web/.gitignore: Cannot open: Not a directory tar: code/web/modules/README.txt: Cannot open: Not a directory tar: code/web/robots.txt: Cannot open: Not a directory tar: code/web/.eslintrc.json: Cannot open: Not a directory tar: code/web/.csslintrc: Cannot open: Not a directory tar: code/web/profiles/README.txt: Cannot open: Not a directory tar: code/web/.ht.router.php: Cannot open: Not a directory tar: code/web/INSTALL.txt: Cannot open: Not a directory tar: code/web/autoload.php: Cannot open: Not a directory tar: code/web/README.md: Cannot open: Not a directory ... tar: code/web/sites/default/settings.php: Cannot open: Not a directory tar: code/web/sites/default/services.yml: Cannot open: Not a directory tar: code/web/sites/default/default.services.yml: Cannot open: Not a directory ... tar: Exiting with failure status due to previous errors

Is this a known issue? Is there any workaround?

Thank you.

quilx

Conditional subelement within custom composite webform element

6 days 12 hours ago

I have a webform that has a custom composite element; let's name it composite_name.

Within that custom composite, I have element_a, element_b, and element_c.

Is it possible to make element_c visible only when a value is entered in either element_a or element_b, by editing the composite element in the Webform UI?

I tried putting this in the custom properties for element_c, but it does not work:

states: visible: - ':input[name=["composite_name"]["element_a"]]': filled: true - or - ':input[name=["composite_name"]["element_b"]]': filled: true

I also tried a few variations on that, with no success. I don't know whether I just have some punctuation out of place or something.

It looks like I could make the condition happen using a custom module (following the webform_example_composite module's code), but I'm hoping to configure it in the UI.

Brian Smith

Drupal Planet