Skip to content

Commit

Permalink
Merge pull request #1475 from tripal/tv4g1-1393-ContentTypesYML-ymlOnly
Browse files Browse the repository at this point in the history
Redo of "Content Types and Fields defined by YAML" focused on minimal changes
  • Loading branch information
laceysanderson committed May 8, 2023
2 parents 7f45866 + f167a01 commit 92aac2e
Show file tree
Hide file tree
Showing 30 changed files with 5,133 additions and 1,156 deletions.
376 changes: 225 additions & 151 deletions tripal/config/schema/tripal.schema.yml

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions tripal/src/Entity/TripalEntityTypeCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Drupal\tripal\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;

/**
* Provides a UI for YML-based TripalEntityType creation.
* Each instance of this entity is a single configuration for tripal content
* types in your site.
*
* @ConfigEntityType(
* id = "tripalentitytype_collection",
* label = @Translation("Tripal Content Type Collection"),
* label_collection = @Translation("Tripal Content Type Collections"),
* label_singular = @Translation("Tripal Content Type Collection"),
* label_plural = @Translation("Tripal Content Type Collections"),
* label_count = @PluralTranslation(
* singular = "@count Tripal Content Type collection",
* plural = "@count Tripal Content Type collections",
* ),
* handlers = {
* "list_builder" = "Drupal\tripal\ListBuilders\TripalEntityTypeCollectionListBuilder",
* "form" = {
* "delete" = "Drupal\tripal\Form\TripalEntityTypeCollectionDeleteForm",
* }
* },
* config_prefix = "tripalentitytype_collection",
* admin_permission = "administer tripal",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* },
* config_export = {
* "id",
* "label",
* "description",
* "content_types"
* },
* links = {
* "delete-form" = "/admin/tripal/config/tripalentitytype-collection/{config}/delete",
* "collection" = "/admin/tripal/config/tripalentitytype-collection"
* }
* )
*/
class TripalEntityTypeCollection extends ConfigEntityBase implements TripalEntityTypeCollectionInterface {

/**
* The TripalEntityTypeCollectionConfig ID.
*
* @var string
*/
protected $id;

/**
* The TripalEntityTypeCollectionConfig label.
*
* @var string
*/
protected $label;

/**
* The TripalEntityTypeCollectionConfig description.
*
* @var string
*/
protected $description;

/**
*
* @var array
*/
protected $content_types;

/**
* Retrieves the current description for the content type configuration.
*
* @return string
*/
public function description() {
return $this->description;
}
}
13 changes: 13 additions & 0 deletions tripal/src/Entity/TripalEntityTypeCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace Drupal\tripal\Entity;

use Drupal\Core\Config\Entity\ConfigEntityInterface;

/**
* Provides a UI for YML-based TripalEntityType creation.
* Each instance of this entity is a single configuration for tripal content
* types in your site.
*/
interface TripalEntityTypeCollectionInterface extends ConfigEntityInterface {
// Add get/set methods for your configuration properties here.
}
80 changes: 80 additions & 0 deletions tripal/src/Entity/TripalFieldCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Drupal\tripal\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;

/**
* Provides a UI for YML-based TripalField creation.
* Each instance of this entity is a single configuration for Tripal Field Collection
* in your site.
*
* @ConfigEntityType(
* id = "tripalfield_collection",
* label = @Translation("Tripal Field Collection"),
* label_collection = @Translation("Tripal Field Collection"),
* handlers = {
* "list_builder" = "Drupal\tripal\ListBuilders\TripalFieldCollectionListBuilder",
* "form" = {
* "add" = "Drupal\tripal\Form\TripalFieldCollectionForm",
* "edit" = "Drupal\tripal\Form\TripalFieldCollectionForm",
* "delete" = "Drupal\tripal\Form\TripalFieldCollectionDeleteForm",
* }
* },
* config_prefix = "tripalfield_collection",
* admin_permission = "administer tripal",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* },
* config_export = {
* "id",
* "label",
* "description",
* "fields"
* },
* links = {
* "collection" = "/admin/tripal/config/tripalfield-collection",
* "delete-form" = "/admin/tripal/config/tripalfield-collection/{config}/delete"
* }
* )
*/
class TripalFieldCollection extends ConfigEntityBase implements TripalFieldCollectionInterface {

/**
* The Config ID.
*
* @var string
*/
protected $id;

/**
* The Config label.
*
* @var string
*/
protected $label;

/**
* The Config description.
*
* @var string
*/
protected $description;

/**
*
* @var array
*/
protected $fields;

/**
* Retrieves the current description.
*
* @return string
*/
public function description() {
return $this->description;
}

}
13 changes: 13 additions & 0 deletions tripal/src/Entity/TripalFieldCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
namespace Drupal\tripal\Entity;

use Drupal\Core\Config\Entity\ConfigEntityInterface;

/**
* Provides a UI for YML-based TripalField creation.
* Each instance of this entity is a single configuration for tripal fields
* in your site.
*/
interface TripalFieldCollectionInterface extends ConfigEntityInterface {
// Add get/set methods for your configuration properties here.
}
54 changes: 54 additions & 0 deletions tripal/src/Form/TripalEntityTypeCollectionDeleteForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Drupal\tripal\Form;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;

/**
* Builds the form to delete an Chado Term Mapping Config Entity.
*/

class TripalEntityTypeCollectionDeleteForm extends EntityConfirmFormBase {

/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}

/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('You are deleting an entire configuration that specifies how ' .
'content types should be created by Tripal. Rebuild the cache to re-import ' .
'the default settings of this configuration.');
}

/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.tripalentitytype_collection.collection');
}

/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
$this->messenger()->addMessage($this->t('The %label Tripal Content Type Collection has been deleted.', ['%label' => $this->entity->label()]));

$form_state->setRedirectUrl($this->getCancelUrl());
}

}
54 changes: 54 additions & 0 deletions tripal/src/Form/TripalFieldCollectionDeleteForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Drupal\tripal\Form;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;

/**
* Builds the form to delete an Chado Term Mapping Config Entity.
*/

class TripalFieldCollectionDeleteForm extends EntityConfirmFormBase {

/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}

/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('You are deleting an entire configuration that specifies how ' .
'fields are attached to content types in Tripal. Rebuild the cache to re-import ' .
'the default settings of this configuration.');
}

/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.tripalfield_collection.collection');
}

/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
$this->messenger()->addMessage($this->t('Entity %label has been deleted.', ['%label' => $this->entity->label()]));

$form_state->setRedirectUrl($this->getCancelUrl());
}

}
37 changes: 37 additions & 0 deletions tripal/src/ListBuilders/TripalEntityTypeCollectionListBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Drupal\tripal\ListBuilders;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;


/**
* Provides a listing of Content Types configurations.
*/
class TripalEntityTypeCollectionListBuilder extends ConfigEntityListBuilder {

/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('Configuration Name');
$header['id'] = $this->t('ID');
$header['description'] = $this->t('Description');
return $header + parent::buildHeader();
}

/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['description'] = $entity->description();

// You probably want a few more properties here...

return $row + parent::buildRow($entity);
}

}
37 changes: 37 additions & 0 deletions tripal/src/ListBuilders/TripalFieldCollectionListBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Drupal\tripal\ListBuilders;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;


/**
* Provides a listing of Tripal Field configurations.
*/
class TripalFieldCollectionListBuilder extends ConfigEntityListBuilder {

/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('Configuration Name');
$header['id'] = $this->t('ID');
$header['description'] = $this->t('Description');
return $header + parent::buildHeader();
}

/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
$row['description'] = $entity->description();

// You probably want a few more properties here...

return $row + parent::buildRow($entity);
}

}

0 comments on commit 92aac2e

Please sign in to comment.