当前位置: 首页>>代码示例>>PHP>>正文


PHP GetResponseEvent::getMigration方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent::getMigration方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent::getMigration方法的具体用法?PHP GetResponseEvent::getMigration怎么用?PHP GetResponseEvent::getMigration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpKernel\Event\GetResponseEvent的用法示例。


在下文中一共展示了GetResponseEvent::getMigration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateTranslations

 /**
  * MigrateEvents::POST_ROW_SAVE event handler.
  *
  * @param GetResponseEvent $event
  *   Instance of Symfony\Component\HttpKernel\Event\GetResponseEvent.
  */
 public function updateTranslations(GetResponseEvent $event)
 {
     $row = $event->getRow();
     $migrate_src_values = $row->getSource();
     $migrate_dest_values = $row->getDestination();
     // Make sure that this post processing is enables for this migration.
     if (!isset($migrate_src_values['constants']['post_save_process']) || $migrate_src_values['constants']['post_save_process'] != 'DonkeymediaMigratePostSave') {
         return $event;
     }
     module_load_include('inc', 'donkeymedia_migrate', 'qtranslate_parser');
     // These are defined in migration.yml.
     $available_languages = $row->getSource()['constants']['available_languages'];
     $default_language = $row->getDestination()['langcode'];
     // Unset default language from available langguages.
     if (($key = array_search($default_language, $available_languages)) !== FALSE) {
         unset($available_languages[$key]);
     }
     $migrated_node = $event->destinationIdValues[0];
     $entity = node_load($migrated_node);
     // Get multilingual fields in all languages.
     $titles = qtrans_split($migrate_src_values['title'], $available_languages);
     $body_values = qtrans_split($migrate_src_values['content:encoded'], $available_languages);
     foreach ($available_languages as $lang) {
         // Preprocess Body:
         // Remove Caption and prepare Image.
         $caption_tags = $this->getTags($body_values[$lang]);
         // Remove Caption.
         $body_value = $this->getTags($body_values[$lang], TRUE);
         // Only add translation if we have some translated Stuff.
         $check_values = isset($titles[$lang]) && strlen($titles[$lang]) > 0 && isset($body_values[$lang]) && strlen($body_values[$lang]) > 0;
         $check_content = TRUE;
         //($titles[$lang] != $entity->getTitle()) || $body_values[$lang] != $entity->get('body');
         $has_images = count($caption_tags['caption']['values']) > 0;
         if ($has_images) {
             $X = FALSE;
         }
         if ($check_values && $check_content) {
             $values = array('created' => $migrate_dest_values['created'], 'uid' => $migrate_dest_values['uid'], 'sticky' => $migrate_dest_values['sticky'], 'status' => $migrate_dest_values['status'], 'title' => $titles[$lang], 'body' => array('value' => $body_value, 'format' => $migrate_dest_values['body']['format']));
             if ($has_images) {
                 $images = array();
                 foreach ($caption_tags['caption']['values'] as $img) {
                     $q = db_select('migrate_map_donkeymedia_file', 'm')->fields('m', array('sourceid1', 'destid1'))->condition('m.sourceid1', $img['attachment'])->execute();
                     $map = $q->fetchObject();
                     $file = \Drupal::entityManager()->getStorage('file')->load($map->destid1);
                     if (is_object($file)) {
                         $image_values = array('target_id' => $file->id(), 'alt' => $img['alt'], 'title' => $img['caption']);
                         $images[] = $image_values;
                         $file = FALSE;
                     } else {
                         trigger_error("Can't find file:", E_USER_WARNING);
                         var_dump($img);
                     }
                 }
                 // Directly setting the values doesn't work :/
                 // $values['field_image'] = $images;
             }
             $translated_entity = $entity->addTranslation($lang, $values);
             if ($has_images && !empty($images)) {
                 $translated_entity->save();
                 $translated_entity->field_image->setValue($images);
                 $translated_entity->setChangedTime($migrate_dest_values['changed']);
                 $translated_entity->save();
             } else {
                 $translated_entity->setChangedTime($migrate_dest_values['changed']);
                 $translated_entity->save();
             }
         }
     }
     $map = $event->getMigration()->getIdMap();
     $map->saveIdMapping($event->getRow(), array($migrated_node));
 }
开发者ID:digitaldonkey,项目名称:donkeymedia_migrate,代码行数:77,代码来源:DonkeymediaMigratePostSave.php


注:本文中的Symfony\Component\HttpKernel\Event\GetResponseEvent::getMigration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。