mazze's picture

Hi, a possible customer wants to upgrade its large D7 site. He made use of the Media CKEditor module in Drupal, which embeds images in WYSYWYG field with code like

<p>[[{"fid":"5916","view_mode":"default","fields":{"format":"default","alignment":"center","field_file_image_alt_text[und][0][value]":false,"field_file_image_title_text[und][0][value]":false},"type":"media","field_deltas":{"2":{"format":"default","alignment":"center","field_file_image_alt_text[und][0][value]":false,"field_file_image_title_text[und][0][value]":false}},"attributes":{"class":"media-element file-default media-wysiwyg-align-center","data-delta":"2"}}]]</p>

Is there any function in Backdrop CMS which converts this code into proper media asset code <img src="..."/>. Or is there any function in D7 to get rid of the module before upgrading?

Any comment is very welcome:-)

Most helpful answers

I've worked on a script that will convert custom blocks (and translations), blocks in layouts, and long text fields (text_long, text_with_summary) in entities. It will convert simple image file entities (with no custom fields) to the embedded image provided by Backdrop; and it converts video file entities (with no custom fields) to Video Filter tokens:

[video:/www.youtube.com/watch?v=123456 width:900 align:left]

Let me know how that works for you and if you have any improvements you can share back.

For now this script does the trick for me but someone is free to adapt it for their own uses or turn it into a friendlier GUI or whatever.

Comments

I don't know of any module that will do it, but I wonder if you could write a custom module that loads every node, runs text area fields through the filters and then resaves the nodes to write the filtered markup into the fields?

I've worked on a script that will convert custom blocks (and translations), blocks in layouts, and long text fields (text_long, text_with_summary) in entities. It will convert simple image file entities (with no custom fields) to the embedded image provided by Backdrop; and it converts video file entities (with no custom fields) to Video Filter tokens:

[video:/www.youtube.com/watch?v=123456 width:900 align:left]

Let me know how that works for you and if you have any improvements you can share back.

For now this script does the trick for me but someone is free to adapt it for their own uses or turn it into a friendlier GUI or whatever.

mazze's picture

Hi Herb, so it took quite some time, but I want to start with the update next week... but I have a very basic question first: how do you apply that script and when you apply it? I am thankful for any hint;-))

Herb's put in the top of the script the usage of it;

bee php-script convert-d7media2backdrop.php

So you would need the 'bee' module installed, which is like Drupal's Drush, and it gets run at command line, therefore not on typical shared hosting, but on a VPS or a localhost development.

mazze's picture

Wow Herb, this is great news. I am in some other projects with tight deadlines, but will have a look at this soon:-) Thank you for sharing!

mazze's picture

I also found a workaround using Views Data Export and Feeds for re-import the nodes. Views CSV exports the proper file link instead of the media module code, an Feed import maps the nodes accordingly:-)