1

Given a source's title like

This "cool" & "neat" article's title has HTML entities

, is creating a title of

This "cool" & "neat" article's title has
HTML entities

Must I create a process plugin to handle this? My migration yml looks somewhat like this:

...
source:
...
    -
      name: title
      label: 'Title'
      selector: title
...
process:
  title: title
...

2 Answers 2

2

It looks like you will have to define a custom process plugin to do this - I can't find any plugin for it on this or this page.

There is a PHP function called htmlspecialchars_decode, which decodes all HTML special character entities, which you can probably use. It takes in a string and returns the decoded string. We also need to pass it the ENT_QUOTES flag for it to convert both double and single quotes.

So you could probably do something like:

namespace Drupal\YOUR_MODULE\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Decode HTML entities.
 * 
 * @MigrateProcessPlugin(
 *   id = "decode_html_entities"
 * )
 */
class DecodeHtmlEntityString extends ProcessPluginBase {

  public function transform(string $value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    return htmlspecialchars_decode($value, ENT_QUOTES);
  }

}
1
  • Thank you Victor F. I ended up implementing a process plugin like yours above. It works perfect but I was surprised that I had to do this step. Sep 17, 2019 at 20:07
0

I solved that with callable plugin:

process:
  title:
    source:
      - g_title
      - ENT_QUOTES
    plugin: callback
    callable: htmlspecialchars_decode
    unpack_source: true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.