Created
July 4, 2016 19:10
-
-
Save adityaanurag/cf1b7efe02c17be75b4b27ca190be72d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\manage_inventory\Entity\Controller; | |
use Drupal\Core\Entity\EntityInterface; | |
use Drupal\Core\Entity\EntityListBuilder; | |
use Drupal\Core\Url; | |
/** | |
* Provides a list controller for content_entity_manage_inventory entity. | |
* | |
* @ingroup manage_inventory | |
*/ | |
class InventoryListBuilder extends EntityListBuilder { | |
/** | |
* {@inheritdoc} | |
* | |
* We override ::render() so that we can add our own content above the table. | |
* parent::render() is where EntityListBuilder creates the table using our | |
* buildHeader() and buildRow() implementations. | |
*/ | |
public function render() { | |
$build['description'] = array( | |
'#markup' => $this->t('Content Entity Example implements a Inventory model. These contacts are fieldable entities. You can manage the fields on the <a href="@adminlink">Inventory admin page</a>.', array( | |
'@adminlink' => \Drupal::urlGenerator() | |
->generateFromRoute('manage_inventory.inventory_settings'), | |
)), | |
); | |
$build['table'] = parent::render(); | |
return $build; | |
} | |
/** | |
* {@inheritdoc} | |
* | |
* Building the header and content lines for the inventory list. | |
* | |
* Calling the parent::buildHeader() adds a column for the possible actions | |
* and inserts the 'edit' and 'delete' links as defined for the entity type. | |
*/ | |
public function buildHeader() { | |
$header['id'] = $this->t('ContactID'); | |
$header['name'] = $this->t('Name'); | |
$header['first_name'] = $this->t('First Name'); | |
$header['gender'] = $this->t('Gender'); | |
return $header + parent::buildHeader(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildRow(EntityInterface $entity) { | |
/* @var $entity \Drupal\manage_inventory\Entity\Inventory */ | |
$row['id'] = $entity->id(); | |
$row['name'] = $entity->link(); | |
$row['first_name'] = $entity->first_name->value; | |
$row['gender'] = $entity->gender->value; | |
return $row + parent::buildRow($entity); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment