I've seen this: Custom entity operation links but it's for Drupal 8 and dealing with nodes whereas mine is a non-node type entity.

So how does one go about adding stuff to the row? I want to add custom operations and basically get control of it but I can't see where to start.

I've extended EntityDefaultUIController in the conventional way (like this). When you go the administrative UI we can debug and break in entity.ui.inc and see the following code snippets which seems to be where this gets invoked. But I've got a feeling that there's a quicker and easier way than adding extended versions of the already existing EntityDefaultUIController functions. But what holds the operations & additional column row information?


within overviewTable(...) ...

foreach ($entities as $entity) {
  $rows[] = $this->overviewTableRow($conditions, entity_id($this->entityType, $entity), $entity);

... which leads us to the following function (same file)

protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {

and we get use of $additional_cols in the 4th (0th + 3 in array speak) parameter but as you can see it's not passed as a parameter above so how do you go about getting this additional information added into the overviewTable?

    // Add in any passed additional cols.
    foreach ($additional_cols as $col) {
        $row[] = $col;

I figured out how do do this, and it, of course, isn't terribly straightforward...

You're on the right track, you just need to override the EntityDefaultUIController::overviewTable function in your own custom class. I don't think there's an easier way (since you're looking for one).

So, copy the the implementation of overviewTable from EntityDefaultUIController (in entity/includes/entity.ui.inc in the Entity API module) into your custom ui controller class and look for the calls to:

$this->overviewTableRow($conditions, entity_id($this->entityType, $entity), $entity);

...and add the $additional_cols parameter which should be an array populated with the extra data (which you can pull from the $entity object already populated in the foreach loop. So, do something like:

foreach ($entities as $entity) {
  $additional_cols = array($entity->someField, $entity->someOtherField);
  $rows[] = $this->overviewTableRow($conditions, entity_id($this->entityType, $entity), $entity, $additional_cols);

In addition to that you'd have to add the associated headers into the render array at the end of the overviewTable function like so...

$additional_headers = array('some field', 'some other field');

$render = array(
  '#theme' => 'table',
  '#header' => $this->overviewTableHeaders($conditions, $rows, $additional_headers),
  '#rows' => $rows,
  '#empty' => t('None.'),

...my guess is that you already figured out this much, but to answer your question, no, I don't think that there's an easier way. I hope this helps you, or someone else. ...or if someone knows this easier way, let me know too... =)


If you want to accomplish this cleaner and with less code, override the overviewTableHeaders and overviewTableRow functions (instead of overviewTable) in your controller class.

class CustomEntityDefaultUIController extends EntityDefaultUIController {

    protected function overviewTableHeaders($conditions, $rows, $additional_header = array()) {
        $additional_header[] = t('My Custom Field');
        $additional_header[] = t('My Other Custom Field');
        return parent::overviewTableHeaders($conditions, $rows, $additional_header);

    protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {
        $additional_cols[] = $entity->my_custom_field;
        $additional_cols[] = $entity->my_other_custom_field;
        return parent::overviewTableRow($conditions, $id, $entity, $additional_cols);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.