DemoTaxonomyTerm.php in Open Social 8.4
Same filename and directory in other branches
- 8.9 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8.2 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8.3 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8.5 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8.6 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8.7 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 8.8 modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 10.3.x modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 10.0.x modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 10.1.x modules/custom/social_demo/src/DemoTaxonomyTerm.php
- 10.2.x modules/custom/social_demo/src/DemoTaxonomyTerm.php
Namespace
Drupal\social_demoFile
modules/custom/social_demo/src/DemoTaxonomyTerm.phpView source
<?php
namespace Drupal\social_demo;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drush\Log\LogLevel;
/**
* Class DemoTaxonomyTerm.
*
* @package Drupal\social_demo
*/
abstract class DemoTaxonomyTerm extends DemoContent {
/**
* DemoTaxonomyTerm constructor.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, DemoContentParserInterface $parser) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->parser = $parser;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('social_demo.yaml_parser'));
}
/**
* {@inheritdoc}
*/
public function createContent() {
$data = $this
->fetchData();
foreach ($data as $uuid => $item) {
// Must have uuid and same key value.
if ($uuid !== $item['uuid']) {
drush_log(dt("Term with uuid: {$uuid} has a different uuid in content."), LogLevel::ERROR);
continue;
}
// Check whether node with same uuid already exists.
$terms = $this->entityStorage
->loadByProperties([
'uuid' => $uuid,
]);
if ($terms) {
drush_log(dt("Term with uuid: {$uuid} already exists."), LogLevel::WARNING);
continue;
}
$entry = $this
->getEntry($item);
$entity = $this->entityStorage
->create($entry);
$entity
->save();
if ($entity
->id()) {
$this->content[$entity
->id()] = $entity;
}
}
return $this->content;
}
/**
* {@inheritdoc}
*/
protected function getEntry(array $item) {
$entry = [
'uuid' => $item['uuid'],
'name' => $item['name'],
'vid' => $item['vid'],
'created' => \Drupal::time()
->getRequestTime(),
];
return $entry;
}
}
Classes
Name | Description |
---|---|
DemoTaxonomyTerm | Class DemoTaxonomyTerm. |