Browse Source

Setup configuration entity (list and create)

Reynold Tan 3 years ago
parent
commit
507626e5ca

+ 1 - 1
config/schema/tripal_blast.schema.yml

@@ -1,7 +1,7 @@
 # @file
 # Tripal Blast Configuration Entity Schema
 
-tripal_blast.blastdb.*:
+tripal_blast.tripalblastdatabase.*:
   type: config_entity
   label: 'BLAST Configuration Entity'
   mapping:

+ 37 - 0
src/Controller/TripalBlastDatabaseListBuilder.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * @file 
+ * This is the controller for Tripal BLAST
+ * Database List Builder (configuration entity).
+ */
+
+namespace Drupal\tripal_blast\Controller;
+
+use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
+use Drupal\Core\Entity\EntityInterface;
+
+/**
+ * Defines TripalBlastDatabaseListBuilder class.
+ * Lists all BLAST database from configuration entity.
+ */
+class TripalBlastDatabaseListBuilder extends ConfigEntityListBuilder {
+  /**
+   * {@inheritdoc}
+   */
+  public function buildHeader() {
+    $header['nid'] = $this->t('Database ID');
+    $header['name'] = $this->t('Blast Database Name');
+
+    return $header + parent::buildHeader();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildRow(EntityInterface $entity) {
+    $row['id'] = $entity->nid();
+    $row['name'] = $entity->name();
+
+    return $row + parent::buildRow($entity);
+  }
+}

+ 96 - 0
src/Entity/TripalBlastDatabase.php

@@ -0,0 +1,96 @@
+<?php
+/**
+ * @file
+ * Contains class definition of Tripal BLAST DB configuration entity.
+ */
+namespace Drupal\tripal_blast\Entity;
+
+use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\tripal_blast\TripalBlastDatabaseInterface;
+
+/**
+ * Defines an image style configuration entity.
+ *
+ * @ConfigEntityType(
+ *   id = "tripalblastdatabase",
+ *   label = @Translation("Tripal Blast Database"),
+ *   handlers = {
+ *     "list_builder" = "Drupal\tripal_blast\Controller\TripalBlastDatabaseListBuilder",
+ *     "form" = {
+ *       "add" = "Drupal\tripal_blast\Form\TripalBlastDatabaseForm"
+ *     }
+ *   },
+ *   admin_permission = "administer tripal",
+ *   config_prefix = "tripal_blast",
+ *   entity_keys = {
+ *     "id" = "nid",
+ *   },
+ *   config_export = {
+ *     "nid",
+ *     "name",
+ *   }
+ * )
+ */
+class TripalBlastDatabase extends ConfigEntityBase implements TripalBlastDatabaseInterface {  
+  /**
+   * The primary identifier for a node.
+   * @var integer
+   */
+  protected $nid;
+
+  /**
+   * The human-readable name of the blast database.
+   * @var string
+   */
+  protected $name;
+
+  /**
+   * The full path and filename prefix of the blast database.
+   * @var string
+   */
+  protected $path;
+
+  /**
+   * Type of the blast database. Should be either n for nucleotide or p for protein.
+   * @var string
+   */
+  protected $dbtype;
+
+  /**
+   * The Regular Expression to use to extract the id from the FASTA header of the BLAST database hit.
+   * @var string
+   */
+  protected $dbxref_id_regexp;
+
+  /**
+   * The Database records from this BLAST Database reference.
+   * @var integer
+   */
+  protected $dbxref_db_id;
+
+  /**
+   * Type of linkout to be used for this database reference.
+   * @var string
+   */
+  protected $dbxref_linkout_type;
+
+  /**
+   * Indicate if CViTjs should be used to display hits on a whole genome.
+   * @var boolean
+   */
+  protected $cvitjs_enabled;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getNid() {
+    return $this->nid;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getName() {
+    return $this->name;
+  }
+}

+ 124 - 0
src/Form/TripalBlastDatabaseForm.php

@@ -0,0 +1,124 @@
+<?php
+/**
+ * @file 
+ * This is the controller for Tripal BLAST Configuration form. 
+ */
+
+namespace Drupal\tripal_blast\Form;
+
+use Drupal\Core\Entity\EntityForm;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Form handler for the Example add and edit forms.
+ * @see and credits to: https://www.drupal.org/node/1809494
+ */
+class TripalBlastDatabaseForm extends EntityForm {
+  /**
+   * Constructs an ExampleForm object.
+   *
+   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
+   *   The entityTypeManager.
+   */
+  public function __construct(EntityTypeManagerInterface $entityTypeManager) {
+    $this->entityTypeManager = $entityTypeManager;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('entity_type.manager')
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function form(array $form, FormStateInterface $form_state) {
+    $form = parent::form($form, $form_state);
+    
+    //
+    // # BLAST DATABASE NAME:
+    $form['fld_text_name'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Tripal BLAST database name'),
+      '#description' => $this->t('The human-readable name of the BLAST database.'),
+      '#required' => TRUE,
+    ];
+
+    //
+    // # BLAST DATABASE PATH:
+    $form['fld_text_path'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Database source path'),
+      '#description' => $this->t('The full path and filename prefix of the BLAST database.'),
+      '#required' => TRUE,
+    ];  
+
+    //
+    // # BLAST DATABASE TYPE:
+    $form['fld_text_type'] = [
+      '#type' => 'select',
+      '#title' => $this->t('Database type'),
+      '#options' => ['n' => 'Nucleotide', 'p' => 'Protein'],
+      '#description' => $this->t('Type of the blast database (Nucleotide or Protein).'),
+    ];
+
+    //
+    // # REGULAR EXPRESSION AND DBXREF:
+    $form['regular_expression'] = [
+      '#type' => 'details',
+      '#title' => $this->t('Regular Expression Key and Database Reference'),
+      '#open' => TRUE
+    ];
+      
+      //
+      // # REGULAR EXPRESSION:
+      $form['regular_expression']['fld_text_dbxref_id_regexp'] = [
+        '#type' => 'textfield',
+        '#title' => $this->t('Extract Regular Expression'),
+        '#description' => $this->t('The Regular Expression to use to extract the id from the FASTA header of the BLAST database hit.'),
+        '#required' => TRUE,  
+      ];
+
+      //
+      // # BLAST DATABASE REFERENCE:
+      $form['regular_expression']['fld_text_dbxref_db_id'] = [
+        '#type' => 'textfield',
+        '#title' => $this->t('BLAST database reference'),
+        '#description' => $this->t('The Database records from this BLAST Database reference.'),
+        '#required' => TRUE,  
+      ];
+    
+      //
+      // # BLAST DATABASE REFERENCE LINKOUT:
+      $form['regular_expression']['fld_text_dbxref_linkout_type'] = [
+        '#type' => 'textfield',
+        '#title' => $this->t('BLAST database reference linkout type'),
+        '#description' => $this->t('Type of linkout to be used for this database reference.'),
+        '#required' => TRUE,  
+      ];
+
+    // # SUPPORT CVITJS:
+    $form['fld_checkbox_cvitjs'] = [
+      '#type' => 'checkbox',
+      '#title' => $this->t('Visualize using CVITJS'),
+      '#description' => $this->t('Indicate if CViTjs should be used to display hits on a whole genome.'),
+      '#default_value' => TRUE,
+    ]; 
+          
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function save(array $form, FormStateInterface $form_state) {
+    
+  }
+}

+ 16 - 0
src/TripalBlastDatabaseInterface.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * @file
+ * Contains class definition of Tripal BLAST Database Interface.
+ */
+namespace Drupal\tripal_blast;
+
+use Drupal\Core\Config\Entity\ConfigEntityInterface;
+
+/**
+ * Provides an interface defining the BLAST database entity.
+ */
+interface TripalBlastDatabaseInterface extends ConfigEntityInterface {  
+  public function getNid();
+  public function getName();
+}

+ 12 - 0
tripal_blast.links.action.yml

@@ -0,0 +1,12 @@
+# @file
+# Tripal BLAST link action definition.
+
+# This will insert an Add button to Tripal BLAST Database 
+# configuration entity - show list of entities page.
+
+entity.tripal_blast.blast_database.add:
+  route_name: 'entity.tripal_blast.blast_database.add'
+  title: 'Add Tripal BLAST Database'
+  appears_on:
+    - entity.tripal_blast.blast_database
+

+ 3 - 3
tripal_blast.links.task.yml

@@ -25,7 +25,7 @@ tripal_blast.tab2:
 
 # Tripal BLAST Entity Configuration Tab.
 tripal_blast.tab3:
-  title: 'Tripal BLAST: Entity Configuration'
-  route_name: entity.tripal_blast.blastdb  
+  title: 'Tripal BLAST: Query Database'
+  route_name: entity.tripal_blast.blast_database  
   base_route: tripal_blast.configuration
-  weight: 1 
+  weight: 2

+ 11 - 3
tripal_blast.routing.yml

@@ -93,10 +93,18 @@ tripal_blast.help:
 
 # Route set below defines routes for the management of 
 # configuration entity (list, add, edit and delete).    
-entity.tripal_blast.blastdb:
-  path: '/admin/tripal/extension/tripal_blast/configuration/entity'
+entity.tripal_blast.blast_database:
+  path: '/admin/tripal/extension/tripal_blast/configuration/tripalblastdatabase'
   defaults:
-    _entity_list: 'blastdb_entity'
+    _entity_list: 'tripalblastdatabase'
     _title: 'Tripal BLAST Query Database'
   requirements:
     _permission: 'administer tripal'
+
+entity.tripal_blast.blast_database.add:
+  path: '/admin/tripal/extension/tripal_blast/configuration/tripalblastdatabase/add'
+  defaults:
+    _entity_form: 'tripalblastdatabase.add'
+    _title: 'Tripal BLAST Add Query Database'
+  requirements:
+    _permission: 'administer tripal'