/** * Upgrade a whole bundle to use video_embed_field. * * @param \Drupal\media_entity\Entity\MediaBundle $bundle * The media bundle object. */ protected function upgradeBundle(MediaBundle $bundle) { // Create a video embed field on the media bundle. VideoEmbedField::createVideoEmbedField($bundle->id()); // Load and update all of the existing media entities. $media_entities = $this->entityQuery->get('media')->condition('bundle', $bundle->id())->execute(); foreach ($media_entities as $media_entity) { $media_entity = Media::load($media_entity); $this->upgradeEntity($media_entity, $bundle->getTypeConfiguration()); } // Update the media bundle type. $bundle->type = 'video_embed_field'; $bundle->save(); }
/** * {@inheritdoc} */ public function setup() { parent::setup(); $this->installConfig(['media_entity']); $this->mediaVideoPlugin = $this->container->get('plugin.manager.media_entity.type')->createInstance('video_embed_field', []); $bundle = MediaBundle::create(['id' => 'video', 'type' => 'video_embed_field']); $bundle->save(); }
/** * Creates media bundle. * * @param array $values * The media bundle values. * * @param string $type_name * (optional) The media type provider plugin that is responsible for * additional logic related to this media). * * @return \Drupal\Core\Entity\EntityInterface * Returns newly created media bundle. */ protected function drupalCreateMediaBundle(array $values = array(), $type_name = 'generic') { if (!isset($values['bundle'])) { $id = strtolower($this->randomMachineName()); } else { $id = $values['bundle']; } $values += array('id' => $id, 'label' => $id, 'type' => $type_name, 'type_configuration' => array(), 'field_map' => array()); $bundle = MediaBundle::create($values); $status = $bundle->save(); $this->assertEqual($status, SAVED_NEW, t('Created media bundle %bundle.', array('%bundle' => $bundle->id()))); return $bundle; }