Profile picture for Admin

Faced up with migration form Drupal 7 to 8(9). Migration process was processed with standart module "upgrade" from UI. The task was to migrate an old image field to media.

Solution was found with hook_update.

First of all check if the image is already present in DB. It could be by the previous runs etc

$medias_thumb = \Drupal::entityTypeManager()



'bundle' => [$convert['media_bundle']],

'name' => $node->{$old_field}->entity->label()]


if (!empty($medias_thumb)) {

$new_field = $convert['new_node_image_field'];

$node->{$new_field}->entity = reset($medias_thumb);



sprintf('Reuse IMAGE_THUMB for node "%s".', $node->getTitle())




If there is no image in the DB load it and create a copy in new field.

if (!empty($medias)) {

$media = reset($medias);

$file_id = $media->field_media_image->target_id;

$file = File::load($file_id);

$new_field = $convert['new_node_image_field'];

$node->{$new_field}->entity = _mymodule_create_media_image_entity(






$media_ids_remove[] = $media->id();


sprintf('Reuse media for node "%s".', $node->getTitle())




Full version of script located here

To run this hook use drush command:

drush php-eval "module_load_install('mymodule_custom'); mymodule_custom_update_8801();"


Вміст цього поля є приватним і не буде доступний широкому загалу.
  888888ba    888888ba   dP     dP   .88888.    .d8888P 
88 `8b 88 `8b 88 88 d8' `8b 88'
a88aaaa8P' a88aaaa8P' 88 .8P 88 88 88baaa.
88 `8b. 88 `8b. 88 d8' 88 db 88 88` `88
88 88 88 88 88 .d8P Y8. Y88P 8b. .d8
dP dP dP dP 888888' `8888PY8b `Y888P'

Уведіть код, зображений у стилі Ascii-Арт.