Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / module / content-entity / src / ExampleTypeListBuilder.php.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleTypeListBuilder.php.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/module/content-entity/src/ExampleTypeListBuilder.php.twig
new file mode 100644 (file)
index 0000000..03aeca5
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace Drupal\{{ machine_name }};
+
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Url;
+
+/**
+ * Defines a class to build a listing of {{ entity_type_label|lower }} type entities.
+ *
+ * @see \Drupal\{{ machine_name }}\Entity\{{ class_prefix }}Type
+ */
+class {{ class_prefix }}TypeListBuilder extends ConfigEntityListBuilder {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildHeader() {
+    $header['title'] = $this->t('Label');
+
+    return $header + parent::buildHeader();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildRow(EntityInterface $entity) {
+    $row['title'] = [
+      'data' => $entity->label(),
+      'class' => ['menu-label'],
+    ];
+
+    return $row + parent::buildRow($entity);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render() {
+    $build = parent::render();
+
+    $build['table']['#empty'] = $this->t(
+      'No {{ entity_type_label|lower }} types available. <a href=":link">Add {{ entity_type_label|lower }} type</a>.',
+      [':link' => Url::fromRoute('entity.{{ entity_type_id }}_type.add_form')->toString()]
+    );
+
+    return $build;
+  }
+
+}