class UrlEncode
URL-encodes the input value.
Example:
process:
  new_url:
    plugin: urlencode
    source: 'http://example.com/a url with spaces.html'
This will convert the source URL 'http://example.com/a url with spaces.html' into 'http://example.com/a%20url%20with%20spaces.html'.
Plugin annotation
@MigrateProcessPlugin(
  id = "urlencode"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase- class \Drupal\migrate\ProcessPluginBase implements \Drupal\migrate\Plugin\MigrateProcessInterface extends \Drupal\Core\Plugin\PluginBase- class \Drupal\migrate\Plugin\migrate\process\UrlEncode extends \Drupal\migrate\ProcessPluginBase
 
 
- class \Drupal\migrate\ProcessPluginBase implements \Drupal\migrate\Plugin\MigrateProcessInterface extends \Drupal\Core\Plugin\PluginBase
 
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of UrlEncode
See also
\Drupal\migrate\Plugin\MigrateProcessInterface
1 file declares its use of UrlEncode
- UrlEncodeTest.php in core/modules/ migrate/ tests/ src/ Unit/ process/ UrlEncodeTest.php 
4 string references to 'UrlEncode'
- d6_file.yml in core/modules/ file/ migrations/ d6_file.yml 
- core/modules/file/migrations/d6_file.yml
- d6_user_picture_file.yml in core/modules/ user/ migrations/ d6_user_picture_file.yml 
- core/modules/user/migrations/d6_user_picture_file.yml
- d7_file.yml in core/modules/ file/ migrations/ d7_file.yml 
- core/modules/file/migrations/d7_file.yml
- d7_file_used.yml in core/modules/ file/ tests/ modules/ file_test_get_ids/ migrations/ d7_file_used.yml 
- core/modules/file/tests/modules/file_test_get_ids/migrations/d7_file_used.yml
File
- 
              core/modules/ migrate/ src/ Plugin/ migrate/ process/ UrlEncode.php, line 32 
Namespace
Drupal\migrate\Plugin\migrate\processView source
class UrlEncode extends ProcessPluginBase {
  
  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    // Only apply to a full URL.
    if (is_string($value) && strpos($value, '://') > 0) {
      // URL encode everything after the hostname.
      $parsed_url = parse_url($value);
      // Fail on seriously malformed URLs.
      if ($parsed_url === FALSE) {
        throw new MigrateException("Value '{$value}' is not a valid URL");
      }
      // Iterate over specific pieces of the URL raw URL encoding each one.
      $url_parts_to_encode = [
        'path',
        'query',
        'fragment',
      ];
      foreach ($parsed_url as $parsed_url_key => $parsed_url_value) {
        if (in_array($parsed_url_key, $url_parts_to_encode)) {
          // urlencode() would convert spaces to + signs.
          $urlencoded_parsed_url_value = rawurlencode($parsed_url_value);
          // Restore special characters depending on which part of the URL this is.
          switch ($parsed_url_key) {
            case 'query':
              $urlencoded_parsed_url_value = str_replace('%26', '&', $urlencoded_parsed_url_value);
              break;
            case 'path':
              $urlencoded_parsed_url_value = str_replace('%2F', '/', $urlencoded_parsed_url_value);
              break;
          }
          $parsed_url[$parsed_url_key] = $urlencoded_parsed_url_value;
        }
      }
      $value = (string) Uri::fromParts($parsed_url);
    }
    return $value;
  }
}Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|
| DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
| DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
| DependencySerializationTrait::__sleep | public | function | 2 | ||
| DependencySerializationTrait::__wakeup | public | function | #[\ReturnTypeWillChange] | 2 | |
| MessengerTrait::$messenger | protected | property | The messenger. | 27 | |
| MessengerTrait::messenger | public | function | Gets the messenger. | 27 | |
| MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
| PluginBase::$configuration | protected | property | Configuration information passed into the plugin. | 1 | |
| PluginBase::$pluginDefinition | protected | property | The plugin implementation definition. | 1 | |
| PluginBase::$pluginId | protected | property | The plugin_id. | ||
| PluginBase::DERIVATIVE_SEPARATOR | constant | A string which is used to separate base plugin IDs from the derivative ID. | |||
| PluginBase::getBaseId | public | function | Gets the base_plugin_id of the plugin instance. | Overrides DerivativeInspectionInterface::getBaseId | |
| PluginBase::getDerivativeId | public | function | Gets the derivative_id of the plugin instance. | Overrides DerivativeInspectionInterface::getDerivativeId | |
| PluginBase::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | Overrides PluginInspectionInterface::getPluginDefinition | 2 | 
| PluginBase::getPluginId | public | function | Gets the plugin_id of the plugin instance. | Overrides PluginInspectionInterface::getPluginId | |
| PluginBase::isConfigurable | public | function | Determines if the plugin is configurable. | ||
| PluginBase::__construct | public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 85 | |
| ProcessPluginBase::multiple | public | function | Indicates whether the returned value requires multiple handling. | Overrides MigrateProcessInterface::multiple | 3 | 
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
| StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
| StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
| StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
| StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
| StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | ||
| UrlEncode::transform | public | function | Performs the associated process. | Overrides ProcessPluginBase::transform | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
