ContentTypeConfigService.php in Content Planner 8
File
modules/content_calendar/src/ContentTypeConfigService.php
View source
<?php
namespace Drupal\content_calendar;
use Drupal\content_calendar\Entity\ContentTypeConfig;
use Drupal\Core\Config\ConfigFactoryInterface;
class ContentTypeConfigService {
protected $configFactory;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public function loadAllEntities() {
return ContentTypeConfig::loadMultiple();
}
public function loadEntityByContentType($content_type) {
if ($entity = ContentTypeConfig::load($content_type)) {
return $entity;
}
return FALSE;
}
public function createEntity($node_type, $label, $color = '#0074bd') {
$entity_build = [
'id' => $node_type,
'label' => $label,
'color' => $color,
];
$entity = ContentTypeConfig::create($entity_build);
return $entity
->save();
}
}