From c44990643e07081b89ff766b62ca6c56b51a2ba3 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 21 Aug 2020 12:00:00 +0100 Subject: [PATCH] Set talk type for existing talks --- .gitignore | 2 +- .../custom/opd_talks/opd_talks.install | 17 +++++++++ .../custom/opd_talks/opd_talks.services.yml | 3 ++ .../src/Repository/TalkRepository.php | 35 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 web/modules/custom/opd_talks/opd_talks.install create mode 100644 web/modules/custom/opd_talks/opd_talks.services.yml create mode 100644 web/modules/custom/opd_talks/src/Repository/TalkRepository.php diff --git a/.gitignore b/.gitignore index af14085..02760d9 100644 --- a/.gitignore +++ b/.gitignore @@ -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/** diff --git a/web/modules/custom/opd_talks/opd_talks.install b/web/modules/custom/opd_talks/opd_talks.install new file mode 100644 index 0000000..2db8d5a --- /dev/null +++ b/web/modules/custom/opd_talks/opd_talks.install @@ -0,0 +1,17 @@ +getAll() as $talk) { + $talk->set('field_type', 'talk'); + $talk->save(); + } +} diff --git a/web/modules/custom/opd_talks/opd_talks.services.yml b/web/modules/custom/opd_talks/opd_talks.services.yml new file mode 100644 index 0000000..c8aebb7 --- /dev/null +++ b/web/modules/custom/opd_talks/opd_talks.services.yml @@ -0,0 +1,3 @@ +services: + Drupal\opd_talks\Repository\TalkRepository: + autowire: true diff --git a/web/modules/custom/opd_talks/src/Repository/TalkRepository.php b/web/modules/custom/opd_talks/src/Repository/TalkRepository.php new file mode 100644 index 0000000..9977e27 --- /dev/null +++ b/web/modules/custom/opd_talks/src/Repository/TalkRepository.php @@ -0,0 +1,35 @@ +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) + ); + } + +}