X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FHookEntityInfo.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FConverter%2FHookEntityInfo.php;h=60f7601c6a24f9d907068e1e1a5e58cb32cdde62;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookEntityInfo.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookEntityInfo.php new file mode 100644 index 000000000..60f7601c6 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Converter/HookEntityInfo.php @@ -0,0 +1,87 @@ +executeHook($target, 'entity_info'); + } + catch (\LogicException $e) { + $this->log->warning($e->getMessage(), [ + 'target' => $target->id(), + 'hook' => $this->pluginDefinition['hook'], + ]); + return; + } + + foreach ($entity_types as $id => $entity_type) { + $entity_type['id'] = $id; + + $entity_type['base_table'] = $entity_type['base table']; + unset($entity_type['base table']); + + $entity_type['keys'] = $entity_type['entity keys']; + unset($entity_type['entity keys']); + + if (isset($entity_type['controller class'])) { + /** @var \Pharborist\Objects\ClassNode $controller */ + $indexer = $target->getIndexer('class'); + if ($indexer->has($entity_type['controller class'])) { + $controller = $indexer->get($entity_type['controller class']); + + $parent = $controller->getExtends(); + if ($parent) { + if ($parent->getText() == 'DrupalDefaultEntityController' || $parent->getText() == 'EntityAPIController') { + $controller->setExtends('Drupal\Core\Entity\Sql\SqlContentEntityStorage'); + } + else { + // @todo Not entirely sure what to do here. It's not a huge problem + // if the controller extends another class defined by the target + // (which is, admittedly, an edge case), but if it extends a + // controller defined by *another* module that isn't Entity API? + } + } + + // @todo Handle interfaces implemented by the entity controller. + + $this->writeClass($target, PSR4::toPSR4($target, $controller)); + $entity_type['controllers']['storage'] = $controller->getName()->getAbsolutePath(); + } + else { + throw new \LogicException(SafeMarkup::format('Cannot get ahold of the controller class for @entity_type entity type.', ['@entity_type' => $id])); + } + } + else { + $entity_type['controllers']['storage'] = 'Drupal\Core\Entity\Sql\SqlContentEntityStorage'; + } + + $render = [ + '#module' => $target->id(), + '#class' => $this->toTitleCase($id), + '#theme' => 'dmu_entity_type', + '#info' => $entity_type, + ]; + $this->writeClass($target, $this->parse($render)); + } + } + +}