X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fmodule%2Fcontent-entity%2Fsrc%2FExampleListBuilder.php.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fmodule%2Fcontent-entity%2Fsrc%2FExampleListBuilder.php.twig;h=0030494221d8cd286a002ab1c1dad0f0d07a7aeb;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleListBuilder.php.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleListBuilder.php.twig new file mode 100644 index 000000000..003049422 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleListBuilder.php.twig @@ -0,0 +1,138 @@ +dateFormatter = $date_formatter; + $this->redirectDestination = $redirect_destination; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity_type.manager')->getStorage($entity_type->id()), + $container->get('date.formatter'), + $container->get('redirect.destination') + ); + } + + /** + * {@inheritdoc} + */ + public function render() { + $build['table'] = parent::render(); + + $total = \Drupal::database() + ->query('SELECT COUNT(*) FROM {{ '{' }}{{ entity_type_id }}{{ '}' }}') + ->fetchField(); + + $build['summary']['#markup'] = $this->t('Total {{ entity_type_label|lower|plural }}: @total', ['@total' => $total]); + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildHeader() { + $header['id'] = $this->t('ID'); +{% if title_base_field %} + $header['title'] = $this->t('Title'); +{% endif %} +{% if status_base_field %} + $header['status'] = $this->t('Status'); +{% endif %} +{% if author_base_field %} + $header['uid'] = $this->t('Author'); +{% endif %} +{% if created_base_field %} + $header['created'] = $this->t('Created'); +{% endif %} +{% if changed_base_field %} + $header['changed'] = $this->t('Updated'); +{% endif %} + return $header + parent::buildHeader(); + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + /* @var $entity \Drupal\{{ machine_name }}\Entity\{{ class_prefix }} */ + $row['id'] = $entity->{{ title_base_field ? 'id' : 'link' }}(); +{% if title_base_field %} + $row['title'] = $entity->link(); +{% endif %} +{% if status_base_field %} + $row['status'] = $entity->isEnabled() ? $this->t('Enabled') : $this->t('Disabled'); +{% endif %} +{% if author_base_field %} + $row['uid']['data'] = [ + '#theme' => 'username', + '#account' => $entity->getOwner(), + ]; +{% endif %} +{% if created_base_field %} + $row['created'] = $this->dateFormatter->format($entity->getCreatedTime()); +{% endif %} +{% if changed_base_field %} + $row['changed'] = $this->dateFormatter->format($entity->getChangedTime()); +{% endif %} + return $row + parent::buildRow($entity); + } + + /** + * {@inheritdoc} + */ + protected function getDefaultOperations(EntityInterface $entity) { + $operations = parent::getDefaultOperations($entity); + $destination = $this->redirectDestination->getAsArray(); + foreach ($operations as $key => $operation) { + $operations[$key]['query'] = $destination; + } + return $operations; + } + +}