12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace Drupal\reinstall\EventSubscriber;
- use Drupal\reinstall\DumperEvent;
- use Drupal\reinstall\DumperEvents;
- use Drupal\taxonomy\TermInterface;
- use Drupal\taxonomy\TermStorageInterface;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- class TermPreDump implements EventSubscriberInterface {
- public static function getSubscribedEvents() {
- return [
- DumperEvents::PRE_DUMP => 'onDumpPre',
- ];
- }
- protected static function setParents(TermInterface $term, $tid, TermStorageInterface $storage) {
- $parents = $storage->loadParents($term->id());
- if (!empty($parents)) {
- $term->set('parent', array_keys($parents));
- }
- }
- public static function onDumpPre(DumperEvent $event) {
- $storage = $event->storage;
- if ($storage->getEntityTypeId() !== 'taxonomy_term') {
- return;
- }
- array_walk($event->entities, [__CLASS__, 'setParents'], $storage);
- }
- }
|