МЛ

Size: a a a
МЛ

МЛ
C
МЛ
C
МЛ
C
МЛ
МЛ
C
МЛ
C
МЛ
abstract class CustomCSVImportPluginBase extends PluginBase implements CustomCSVImportPluginInterface, ContainerFactoryPluginInterface {
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager = NULL, FileSystemInterface $file_system = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('file_system')
);
}C
МЛ
$this->entityTypeManager->getStorage('taxonomy_term');C
МЛ
/**
* Load for edit or create new entity by unique id from CSV.
*
* @param $id
* Unique ID in CSV file.
* @param $entity_type
* The entity type id.
* @param $bundle
* The bundle of entity type.
* @param $field_id
* Proxy field`s name of unique id from CSV for edit.
*
* @return \Drupal\Core\Entity\EntityInterface|null
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected function getContentEntityByUid($id, $entity_type, $bundle, $field_id) {
$storage = $this->entityTypeManager->getStorage($entity_type);
$bundle_name = $this->getContentBundleName();
$eid = $storage->getQuery()
->condition($bundle_name, $bundle)
->condition($field_id, $id)
->execute();
if (!empty($eid)) {
$entity = $storage->load($eid[key($eid)]);
}
else {
$entity = $storage->create([
$bundle_name => $bundle,
'langcode' => 'en',
'uid' => 1,
'status' => 1,
]);
$entity->set($field_id, $id);
}
return $entity;
}
C
МЛ
МЛ