ZZ is the fallback address format and it must always be present.

We need an access handler that returns always returns FALSE when trying to delete the ZZ address format.
We should also extend the storage to throw an exception if "ZZ" is passed to the delete method.

The testAddressFormatDeleteZZ test should be extended to attempt a delete through the API as well.

Comments

bojanz created an issue. See original summary.

dbolinovski’s picture

Status: Active » Needs review
StatusFileSize
new4.22 KB
dbolinovski’s picture

Overriding delete() from ConfigEntityStorage.

  • bojanz committed 7bc5f5f on 8.x-1.x authored by dbolinovski
    Issue #2562395 by dbolinovski: Prevent the ZZ address format from being...
bojanz’s picture

Status: Needs review » Fixed

Committed, thanks.

I swapped the delete() method in the storage for a doDelete() one because in delete() $entities are not guaranteed to be keyed by id.

joshtaylor’s picture

This now means that address cannot be uninstalled.

exception 'Drupal\Core\Entity\EntityStorageException' with message 'The 'ZZ' address format can't be deleted.' in                                                   [error]
/home/josh/web/address2/modules/address/src/AddressFormatStorage.php:24
Stack trace:
#0 /home/josh/web/address2/core/lib/Drupal/Core/Entity/EntityStorageBase.php(368): Drupal\address\AddressFormatStorage->doDelete(Array)
#1 /home/josh/web/address2/core/lib/Drupal/Core/Entity/Entity.php(348): Drupal\Core\Entity\EntityStorageBase->delete(Array)
#2 /home/josh/web/address2/core/lib/Drupal/Core/Config/ConfigManager.php(204): Drupal\Core\Entity\Entity->delete()
#3 /home/josh/web/address2/core/lib/Drupal/Core/Extension/ModuleInstaller.php(384): Drupal\Core\Config\ConfigManager->uninstall('module', 'address')
#4 /home/josh/web/address2/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(95): Drupal\Core\Extension\ModuleInstaller->uninstall(Array, true)
#5 /home/josh/.composer/vendor/drush/drush/commands/core/drupal/environment.inc(226): Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall(Array)
#6 /home/josh/.composer/vendor/drush/drush/commands/core/drupal/pm_8.inc(80): drush_module_uninstall(Array)
#7 /home/josh/.composer/vendor/drush/drush/commands/pm/pm.drush.inc(1190): _drush_pm_uninstall(Array)
#8 [internal function]: drush_pm_uninstall('address')
#9 /home/josh/.composer/vendor/drush/drush/includes/command.inc(364): call_user_func_array('drush_pm_uninst...', Array)
#10 /home/josh/.composer/vendor/drush/drush/includes/command.inc(215): _drush_invoke_hooks(Array, Array)
#11 [internal function]: drush_command('address')
#12 /home/josh/.composer/vendor/drush/drush/includes/command.inc(183): call_user_func_array('drush_command', Array)
#13 /home/josh/.composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(62): drush_dispatch(Array)
#14 /home/josh/.composer/vendor/drush/drush/drush.php(70): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#15 /home/josh/.composer/vendor/drush/drush/drush.php(11): drush_main()
#16 {main}

bojanz’s picture

Status: Fixed » Needs work

Wow :)

This is the triggering code:

$entity->setUninstalling(TRUE);
$entity->delete();

So our checks need to also check $entity->isUninstalling().

  • joshtaylor committed a41ca9f on 8.x-1.x
    Issue #2562395 by joshtaylor, bojanz: Address cannot be uninstalled
    
joshtaylor’s picture

Can now uninstall.

josh@jt:~/web/address$ drush en -y address ; drush pmu -y address
The following extensions will be enabled: address
Do you really want to continue? (y/n): y
address was enabled successfully.                                                                                                                [ok]
address defines the following permissions: administer address formats, administer zones
The following extensions will be uninstalled: address
Do you really want to continue? (y/n): y
address was successfully uninstalled.                                                                                                            [ok]
joshtaylor’s picture

Status: Needs work » Closed (fixed)