Set talk type for existing talks
This commit is contained in:
parent
239b2c071c
commit
c44990643e
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -13,7 +13,7 @@
|
|||
!/scripts/
|
||||
!/slides/
|
||||
!/tools/
|
||||
!/web/modules/custom/
|
||||
!/web/modules/custom/**
|
||||
!/web/sites/default/environments/settings.*.php
|
||||
!/web/sites/default/settings.php
|
||||
!/web/themes/custom/**
|
||||
|
|
17
web/modules/custom/opd_talks/opd_talks.install
Normal file
17
web/modules/custom/opd_talks/opd_talks.install
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Drupal\opd_talks\Repository\TalkRepository;
|
||||
|
||||
/**
|
||||
* Set talk type for all existing talks.
|
||||
*/
|
||||
function opd_talks_update_8001(): void {
|
||||
$talkRepository = \Drupal::service(TalkRepository::class);
|
||||
|
||||
foreach ($talkRepository->getAll() as $talk) {
|
||||
$talk->set('field_type', 'talk');
|
||||
$talk->save();
|
||||
}
|
||||
}
|
3
web/modules/custom/opd_talks/opd_talks.services.yml
Normal file
3
web/modules/custom/opd_talks/opd_talks.services.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
services:
|
||||
Drupal\opd_talks\Repository\TalkRepository:
|
||||
autowire: true
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_talks\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\custom\Entity\Node\Talk;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
final class TalkRepository {
|
||||
|
||||
private EntityStorageInterface $nodeStorage;
|
||||
|
||||
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
|
||||
$this->nodeStorage = $entityTypeManager->getStorage('node');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Talk[]
|
||||
*/
|
||||
public function getAll(bool $publishedOnly = FALSE): Collection {
|
||||
$properties = ['type' => 'talk'];
|
||||
|
||||
if ($publishedOnly) {
|
||||
$properties['status'] = TRUE;
|
||||
}
|
||||
|
||||
return new Collection(
|
||||
$this->nodeStorage->loadByProperties($properties)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue