You are here

class LinkInternalContentImporter in Entity Share 8.3

Import internal content from Link fields.

Act in prepare_importable_entity_data stage and not process_entity stage to be effective before entity denormalization.

Plugin annotation


@ImportProcessor(
  id = "link_internal_content_importer",
  label = @Translation("Link internal content"),
  description = @Translation("Import internal content from link fields. Require the 'UUID for link (link field only) (Entity Share)' field enhancer enabled on both client and server websites."),
  stages = {
    "prepare_importable_entity_data" = 20,
  },
  locked = false,
)

Hierarchy

Expanded class hierarchy of LinkInternalContentImporter

File

modules/entity_share_client/src/Plugin/EntityShareClient/Processor/LinkInternalContentImporter.php, line 26

Namespace

Drupal\entity_share_client\Plugin\EntityShareClient\Processor
View source
class LinkInternalContentImporter extends EntityReference {

  /**
   * {@inheritdoc}
   */
  public function prepareImportableEntityData(RuntimeImportContext $runtime_import_context, array &$entity_json_data) {
    if (isset($entity_json_data['attributes']) && is_array($entity_json_data['attributes'])) {
      foreach ($entity_json_data['attributes'] as $field_name => $field_data) {
        if (is_array($field_data)) {
          if (EntityShareUtility::isNumericArray($field_data)) {
            foreach ($field_data as $delta => $value) {
              if (isset($value['content_entity_href'])) {
                $entity_json_data['attributes'][$field_name][$delta]['uri'] = $this
                  ->processLink($runtime_import_context, $value['uri'], $value['content_entity_href']);
              }
            }
          }
          elseif (isset($field_data['content_entity_href'])) {
            $entity_json_data['attributes'][$field_name]['uri'] = $this
              ->processLink($runtime_import_context, $field_data['uri'], $field_data['content_entity_href']);
          }
        }
      }
    }
  }

  /**
   * Attempts to import UUID-enhanced link content.
   *
   * @param \Drupal\entity_share_client\RuntimeImportContext $runtime_import_context
   *   The import context.
   * @param string $uri
   *   URI should be in the format entity:[entity_type]/[bundle_name]/[UUID].
   * @param string $import_url
   *   The import URL prepared by the entity_share_uuid_link enhancer plugin.
   *
   * @return string
   *   Link to the imported content in the form entity:[entity_type]/[Id].
   */
  protected function processLink(RuntimeImportContext $runtime_import_context, string $uri, string $import_url) {

    // Check if it is a link to an entity.
    preg_match("/entity:(.*)\\/(.*)\\/(.*)/", $uri, $parsed_uri);

    // If the link is not in UUID enhanced format, just return the original URI.
    if (empty($parsed_uri)) {
      return $uri;
    }
    $entity_type = $parsed_uri[1];
    $entity_uuid = $parsed_uri[3];
    $referenced_entities_ids = $this
      ->importUrl($runtime_import_context, $import_url);
    if (!empty($referenced_entities_ids) && isset($referenced_entities_ids[$entity_uuid])) {
      return 'entity:' . $entity_type . '/' . $referenced_entities_ids[$entity_uuid];
    }
    else {
      return $uri;
    }
  }

}

Members

Namesort descending Modifiers Type Description 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 1
DependencySerializationTrait::__wakeup public function 2
EntityReference::$currentRecursionDepth protected property The current recursion depth.
EntityReference::$entityReferenceHelper protected property Entity reference helper service.
EntityReference::$entityTypeManager protected property The entity type manager.
EntityReference::$eventDispatcher protected property The event dispatcher service.
EntityReference::$logger protected property Logger.
EntityReference::$remoteManager protected property The remote manager.
EntityReference::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
EntityReference::create public static function Creates an instance of the plugin. Overrides ImportProcessorPluginBase::create
EntityReference::defaultConfiguration public function Gets default configuration for this plugin. Overrides ImportProcessorPluginBase::defaultConfiguration
EntityReference::getExistingEntities protected function Helper function to get existing reference entities.
EntityReference::importUrl protected function Helper function. 1
EntityReference::processEntity public function Method called on STAGE_PROCESS_ENTITY. Overrides ImportProcessorPluginBase::processEntity
ImportProcessorInterface::STAGE_IS_ENTITY_IMPORTABLE constant Processing stage: is entity importable.
ImportProcessorInterface::STAGE_POST_ENTITY_SAVE constant Processing stage: post entity save.
ImportProcessorInterface::STAGE_PREPARE_ENTITY_DATA constant Processing stage: prepare entity data.
ImportProcessorInterface::STAGE_PREPARE_IMPORTABLE_ENTITY_DATA constant Processing stage: prepare importable entity data.
ImportProcessorInterface::STAGE_PROCESS_ENTITY constant Processing stage: process entity.
ImportProcessorPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ImportProcessorPluginBase::getDescription public function Returns the plugin's description. Overrides ImportProcessorInterface::getDescription
ImportProcessorPluginBase::getWeight public function Returns the weight for a specific processing stage. Overrides ImportProcessorInterface::getWeight
ImportProcessorPluginBase::isEntityImportable public function Method called on STAGE_IS_ENTITY_IMPORTABLE. Overrides ImportProcessorInterface::isEntityImportable 2
ImportProcessorPluginBase::isLocked public function Determines whether this processor should always be enabled. Overrides ImportProcessorInterface::isLocked
ImportProcessorPluginBase::label public function Returns the label for use on the administration pages. Overrides ImportProcessorInterface::label
ImportProcessorPluginBase::postEntitySave public function Method called on STAGE_POST_ENTITY_SAVE. Overrides ImportProcessorInterface::postEntitySave 1
ImportProcessorPluginBase::prepareEntityData public function Method called on STAGE_PREPARE_ENTITY_DATA. Overrides ImportProcessorInterface::prepareEntityData
ImportProcessorPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ImportProcessorPluginBase::setWeight public function Sets the weight for a specific processing stage. Overrides ImportProcessorInterface::setWeight
ImportProcessorPluginBase::submitConfigurationForm public function Form submission handler.
ImportProcessorPluginBase::supportsStage public function Checks whether this processor implements a particular stage. Overrides ImportProcessorInterface::supportsStage
ImportProcessorPluginBase::validateConfigurationForm public function Form validation handler.
LinkInternalContentImporter::prepareImportableEntityData public function Method called on STAGE_PREPARE_IMPORTABLE_ENTITY_DATA. Overrides ImportProcessorPluginBase::prepareImportableEntityData
LinkInternalContentImporter::processLink protected function Attempts to import UUID-enhanced link content.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
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 3
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. 92
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.