Skip to main content
Update answer to work for both single and double quotes
Source Link
user78966
user78966

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);
  }

}

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.

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);
  }

}

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);
  }

}
Source Link
user78966
user78966

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.

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);
  }

}