localgovdrupal / localgov_workflows

Default editorial workflow for LocalGov Drupal content.
GNU General Public License v2.0
0 stars 1 forks source link

Error with node_type_insert (missing workflow) on config import #32

Open andybroomfield opened 2 years ago

andybroomfield commented 2 years ago

When doing a config install of the site, the node type imports fail due to the missing editorial workflow. It's not major as the editorial workflow is installed later and the is set up as part of the exported config. However we should check that the workflow exists before adding it.

Its line 96 on localgov_workflows.module. $type = $editorial->getTypePlugin(); My temp solution was to check if it was empty so I could bypass and run the config install.

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function localgov_workflows_node_type_insert(NodeTypeInterface $node_type) {
  // Add workflow to new localgov_ node bundle with no other workflow.
  if (strpos($node_type->id(), 'localgov_') === 0) {
    $types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('node');
    if (empty($types['node']['workflow'])) {
      $editorial = Workflow::load('localgov_editorial');
      if (!empty($editorial)) {
        $type = $editorial->getTypePlugin();
        $type->addEntityTypeAndBundle('node', $node_type->id());
        $editorial->save();
      }
    }
  }
}

Stack trace.

Error: Call to a member function getTypePlugin() on null in localgov_workflows_node_type_insert() (line 96 of /Users/Andy/Sites/bhcclocalgov/docroot/modules/contrib/localgov_workflows/localgov_workflows.module) #0 [internal function]: localgov_workflows_node_type_insert(Object(Drupal\node\Entity\NodeType))
#1 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('localgov_workfl...', Array)
#2 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(337): Drupal\Core\Extension\ModuleHandler->invokeAll('node_type_inser...', Array)
#3 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(602): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('insert', Object(Drupal\node\Entity\NodeType))
#4 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(527): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\node\Entity\NodeType), false)
#5 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(253): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\node\Entity\NodeType))
#6 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\node\Entity\NodeType))
#7 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(607): Drupal\Core\Entity\EntityBase->save()
#8 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(354): Drupal\Core\Config\Entity\ConfigEntityBase->save()
#9 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(992): Drupal\Core\Config\Entity\ConfigEntityStorage->importCreate('node.type.local...', Object(Drupal\Core\Config\Config), Object(Drupal\Core\Config\Config))
#10 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(778): Drupal\Core\Config\ConfigImporter->importInvokeOwner('', 'create', 'node.type.local...')
#11 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(605): Drupal\Core\Config\ConfigImporter->processConfiguration('', 'create', 'node.type.local...')
#12 /Users/Andy/Sites/bhcclocalgov/docroot/core/lib/Drupal/Core/Config/ConfigImporter.php(509): Drupal\Core\Config\ConfigImporter->processConfigurations(Array)
#13 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(336): Drupal\Core\Config\ConfigImporter->doSyncStep('processConfigur...', Array)
#14 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/includes/drush.inc(206): Drush\Drupal\Commands\config\ConfigImportCommands->doImport(Object(Drupal\Core\Config\StorageComparer))
#15 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/includes/drush.inc(197): drush_call_user_func_array(Array, Array)
#16 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/src/Drupal/Commands/config/ConfigImportCommands.php(307): drush_op(Array, Object(Drupal\Core\Config\StorageComparer))
#17 [internal function]: Drush\Drupal\Commands\config\ConfigImportCommands->import(NULL, Array)
#18 /Users/Andy/Sites/bhcclocalgov/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#19 /Users/Andy/Sites/bhcclocalgov/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#20 /Users/Andy/Sites/bhcclocalgov/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#21 /Users/Andy/Sites/bhcclocalgov/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(350): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#22 /Users/Andy/Sites/bhcclocalgov/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /Users/Andy/Sites/bhcclocalgov/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /Users/Andy/Sites/bhcclocalgov/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /Users/Andy/Sites/bhcclocalgov/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#29 /Users/Andy/Sites/bhcclocalgov/vendor/drush/drush/drush(4): require('/Users/Andy/Sit...')
#30 {main}.