Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * Find the parent link GUID.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $parent_id = array_shift($value);
     if (!$parent_id) {
         // Top level item.
         return '';
     }
     try {
         $already_migrated_id = $this->migrationPlugin->transform($parent_id, $migrate_executable, $row, $destination_property);
         if ($already_migrated_id && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
             return $link->getPluginId();
         }
     } catch (MigrateSkipRowException $e) {
     }
     if (isset($value[1])) {
         list($menu_name, $parent_link_path) = $value;
         $url = Url::fromUserInput("/{$parent_link_path}");
         if ($url->isRouted()) {
             $links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name);
             if (count($links) == 1) {
                 /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
                 $link = reset($links);
                 return $link->getPluginId();
             }
         }
     }
     throw new MigrateSkipRowException();
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     list($old_visibility, $pages, $roles) = $value;
     $visibility = array();
     // If the block is assigned to specific roles, add the user_role condition.
     if ($roles) {
         $visibility['user_role'] = array('id' => 'user_role', 'roles' => array(), 'context_mapping' => array('user' => '@user.current_user_context:current_user'), 'negate' => FALSE);
         foreach ($roles as $key => $role_id) {
             $roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
         }
         $visibility['user_role']['roles'] = array_combine($roles, $roles);
     }
     if ($pages) {
         // 2 == BLOCK_VISIBILITY_PHP in Drupal 6 and 7.
         if ($old_visibility == 2) {
             // If the PHP module is present, migrate the visibility code unaltered.
             if ($this->moduleHandler->moduleExists('php')) {
                 $visibility['php'] = array('id' => 'php', 'negate' => FALSE, 'php' => $pages);
             } elseif ($this->skipPHP) {
                 throw new MigrateSkipRowException();
             }
         } else {
             $paths = preg_split("(\r\n?|\n)", $pages);
             foreach ($paths as $key => $path) {
                 $paths[$key] = $path === '<front>' ? $path : '/' . ltrim($path, '/');
             }
             $visibility['request_path'] = array('id' => 'request_path', 'negate' => !$old_visibility, 'pages' => implode("\n", $paths));
         }
     }
     return $visibility;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  *
  * Set the block plugin id.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     if (is_array($value)) {
         list($module, $delta) = $value;
         switch ($module) {
             case 'aggregator':
                 list($type, $id) = explode('-', $delta);
                 if ($type == 'feed') {
                     return 'aggregator_feed_block';
                 }
                 break;
             case 'menu':
                 return "system_menu_block:{$delta}";
             case 'block':
                 if ($this->blockContentStorage) {
                     $block_id = $this->migrationPlugin->transform($delta, $migrate_executable, $row, $destination_property);
                     if ($block_id) {
                         return 'block_content:' . $this->blockContentStorage->load($block_id)->uuid();
                     }
                 }
                 break;
             default:
                 break;
         }
     } else {
         return $value;
     }
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  *
  * Migrate filter format serial to string id in permission name.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $rid = $row->getSourceProperty('rid');
     if ($formats = $row->getSourceProperty("filter_permissions:{$rid}")) {
         foreach ($formats as $format) {
             $new_id = $this->migrationPlugin->transform($format, $migrate_executable, $row, $destination_property);
             if ($new_id) {
                 $value[] = 'use text format ' . $new_id;
             }
         }
     }
     return $value;
 }
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     list($roles) = $value;
     // Remove role IDs disabled in D6/D7.
     $roles = array_filter($roles);
     $user_role_roles = array();
     if ($roles) {
         foreach ($roles as $key => $role_id) {
             $roles[$key] = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
         }
         $user_role_roles = array_combine($roles, $roles);
     }
     return $user_role_roles;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  *
  * Set the block visibility settings.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     list($pages, $roles, $old_visibility) = $value;
     $visibility = array();
     if (!empty($pages)) {
         $visibility['request_path']['pages'] = $pages;
         $visibility['request_path']['id'] = 'request_path';
         $visibility['request_path']['negate'] = !$old_visibility;
     }
     if (!empty($roles)) {
         foreach ($roles as $key => $role_id) {
             $new_role = $this->migrationPlugin->transform($role_id, $migrate_executable, $row, $destination_property);
             $visibility['user_role']['roles'][$new_role] = $new_role;
         }
         $visibility['user_role']['id'] = 'user_role';
         $visibility['user_role']['context_mapping']['user'] = '******';
     }
     return $visibility;
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $options = unserialize($value['data']);
     // Try to look up the ID of the migrated file. If one cannot be found, it
     // means the file referenced by the current field item did not migrate for
     // some reason -- file migration is notoriously brittle -- and we do NOT
     // want to send invalid file references into the field system (it causes
     // fatals), so return an empty item instead.
     try {
         $fid = $this->migrationPlugin->transform($value['fid'], $migrate_executable, $row, $destination_property);
     } catch (MigrateSkipRowException $e) {
         return [];
     }
     if ($fid) {
         return ['target_id' => $fid, 'display' => $value['list'], 'description' => isset($options['description']) ? $options['description'] : '', 'alt' => isset($options['alt']) ? $options['alt'] : '', 'title' => isset($options['title']) ? $options['title'] : ''];
     } else {
         return [];
     }
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     // If we're stubbing a file entity, return a URI of NULL so it will get
     // stubbed by the general process.
     if ($row->isStub()) {
         return NULL;
     }
     list($source, $destination) = $value;
     // If the source path or URI represents a remote resource, delegate to the
     // download plugin.
     if (!$this->isLocalUri($source)) {
         return $this->downloadPlugin->transform($value, $migrate_executable, $row, $destination_property);
     }
     // Ensure the source file exists, if it's a local URI or path.
     if (!file_exists($source)) {
         throw new MigrateException("File '{$source}' does not exist");
     }
     // If the start and end file is exactly the same, there is nothing to do.
     if ($this->isLocationUnchanged($source, $destination)) {
         return $destination;
     }
     $replace = $this->getOverwriteMode();
     // We attempt the copy/move first to avoid calling file_prepare_directory()
     // any more than absolutely necessary.
     $final_destination = $this->writeFile($source, $destination, $replace);
     if ($final_destination) {
         return $final_destination;
     }
     // If writeFile didn't work, make sure there's a writable directory in
     // place.
     $dir = $this->getDirectory($destination);
     if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
         throw new MigrateException("Could not create or write to directory '{$dir}'");
     }
     $final_destination = $this->writeFile($source, $destination, $replace);
     if ($final_destination) {
         return $final_destination;
     }
     throw new MigrateException("File {$source} could not be copied to {$destination}");
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     return $row->getSourceProperty('picture') ? $this->migrationPlugin->transform($value, $migrate_executable, $row, $destination_property) : NULL;
 }