Version 1
[yaffs-website] / web / core / modules / node / src / NodeTypeListBuilder.php
diff --git a/web/core/modules/node/src/NodeTypeListBuilder.php b/web/core/modules/node/src/NodeTypeListBuilder.php
new file mode 100644 (file)
index 0000000..be6e5f6
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+namespace Drupal\node;
+
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
+use Drupal\Core\Url;
+use Drupal\Core\Entity\EntityInterface;
+
+/**
+ * Defines a class to build a listing of node type entities.
+ *
+ * @see \Drupal\node\Entity\NodeType
+ */
+class NodeTypeListBuilder extends ConfigEntityListBuilder {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildHeader() {
+    $header['title'] = t('Name');
+    $header['description'] = [
+      'data' => t('Description'),
+      'class' => [RESPONSIVE_PRIORITY_MEDIUM],
+    ];
+    return $header + parent::buildHeader();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildRow(EntityInterface $entity) {
+    $row['title'] = [
+      'data' => $entity->label(),
+      'class' => ['menu-label'],
+    ];
+    $row['description']['data'] = ['#markup' => $entity->getDescription()];
+    return $row + parent::buildRow($entity);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getDefaultOperations(EntityInterface $entity) {
+    $operations = parent::getDefaultOperations($entity);
+    // Place the edit operation after the operations added by field_ui.module
+    // which have the weights 15, 20, 25.
+    if (isset($operations['edit'])) {
+      $operations['edit']['weight'] = 30;
+    }
+    return $operations;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render() {
+    $build = parent::render();
+    $build['table']['#empty'] = $this->t('No content types available. <a href=":link">Add content type</a>.', [
+        ':link' => Url::fromRoute('node.type_add')->toString()
+      ]);
+    return $build;
+  }
+
+}