EmbeddedEntityImporter.php in Entity Share 8.3
File
modules/entity_share_client/src/Plugin/EntityShareClient/Processor/EmbeddedEntityImporter.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_client\Plugin\EntityShareClient\Processor;
use Drupal\Component\Utility\UrlHelper;
use Drupal\entity_share\EntityShareUtility;
use Drupal\entity_share_client\RuntimeImportContext;
class EmbeddedEntityImporter extends EntityReference {
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_data) {
if (is_array($field_data)) {
if (EntityShareUtility::isNumericArray($field_data)) {
foreach ($field_data as $value) {
if (isset($value['format']) && isset($value['value'])) {
$this
->parseFormattedTextAndImport($runtime_import_context, $value['value']);
}
}
}
elseif (isset($field_data['format']) && isset($field_data['value'])) {
$this
->parseFormattedTextAndImport($runtime_import_context, $field_data['value']);
}
}
}
}
}
protected function parseFormattedTextAndImport(RuntimeImportContext $runtime_import_context, $text) {
$matches = [];
preg_match_all('# data-entity-jsonapi-url="(.*)"#U', $text, $matches);
foreach ($matches[1] as $url) {
if (UrlHelper::isValid($url)) {
$this
->importUrl($runtime_import_context, $url);
}
}
}
}