<p>You don't need to return anything in an event. As you can see how the Event is triggert</p>

<pre><code>Event::trigger(static::class, self::EVENT_REGISTER_TABLE_ATTRIBUTES, $event);
</code></pre>

<p>It does not expect any return value. So you don't add something by returning an array. Instead you'll have to manipulate the properties of your <code>event</code></p>

<p>When you take a look at your <code>RegisterElementTableAttributesEvent</code> it contains the following property</p>

<pre><code>/**
 * @var array List of registered table attributes for the element type.
 */
public $tableAttributes = [];
</code></pre>

<p>In order to add attributes you have to do </p>

<pre><code>Event::on(
    Element::class,
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES,
    function(craft\events\RegisterElementTableAttributesEvent $e) {
        $e-&gt;tableAttributes['foo'] = [
            'label' =&gt; "Foo"
        ];
});
</code></pre>

<p>It's the same for your <code>SetElementTableAttributeHtmlEvent</code>. It has the properties </p>

<pre><code>// Properties
// =========================================================================

/**
 * @var array|null The table attribute associated with this event.
 */
public $attribute;

/**
 * @var string|null The HTML to represent a table attribute.
 */
public $html;
</code></pre>

<p>You can <code>var_dump</code> the <code>$event</code> to see the current properties to get to know which structure you have to include. Usually you would do</p>

<pre><code>Event::on(
    Entry::class,
    Element::EVENT_SET_TABLE_ATTRIBUTE_HTML,
    function(craft\events\SetElementTableAttributeHtmlEvent $e) {
        if($e-&gt;attribute === 'foo'){
            $e-&gt;html = 'FOOOOO';
        }
    }
);
</code></pre>

CC BY-SA 3.0
2018-03-23T13:34:56.790Z
2018-03-23T13:41:59.167Z
2018-03-23T13:41:59.167Z
Robin Schambach
<p>I am developing a plugin to add custom column to entries table for which I am using <code>EVENT_REGISTER_TABLE_ATTRIBUTES</code> and <code>EVENT_SET_TABLE_ATTRIBUTE_HTML</code> and code example is:</p>

<pre><code>Event::on(
    Element::class, 
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES, 
    function(craft\events\RegisterElementTableAttributesEvent $e) {
        return array(
            'foo' =&gt; "Foo",
            'bar' =&gt; "Bar",
        );
});
Event::on(
    Entry::class, 
    Element::EVENT_SET_TABLE_ATTRIBUTE_HTML, 
    function(craft\events\SetElementTableAttributeHtmlEvent $e) {
        if ($e-&gt;attribute === 'foo') {
            return 'bar';
        }
});
</code></pre>

<p>Unfortunately, its not working. Could anyone please help what I am mistaking here. </p>

<plugin-development><craft3>
EVENT_REGISTER_TABLE_ATTRIBUTES not working in Craft 3
# EVENT_REGISTER_TABLE_ATTRIBUTES not working in Craft 3

(Asked by: username_0 on 2018-03-23)

I am developing a plugin to add custom column to entries table for which I am using EVENT_REGISTER_TABLE_ATTRIBUTES and EVENT_SET_TABLE_ATTRIBUTE_HTML and code example is:
Event::on(
    Element::class, 
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES, 
    function(craft\events\RegisterElementTableAttributesEvent $e) {
        return array(
            'foo' => "Foo",
            'bar' => "Bar",
        );
});
Event::on(
    Entry::class, 
    Element::EVENT_SET_TABLE_ATTRIBUTE_HTML, 
    function(craft\events\SetElementTableAttributeHtmlEvent $e) {
        if ($e->attribute === 'foo') {
            return 'bar';
        }
});

Unfortunately, its not working. Could anyone please help what I am mistaking here.

**Tags:** plugin-development, craft3


---

## 1 answers

### Answer by username_1 on 2018-03-23. Score: 3 | Accepted answer

You don't need to return anything in an event. As you can see how the Event is triggert
Event::trigger(static::class, self::EVENT_REGISTER_TABLE_ATTRIBUTES, $event);

It does not expect any return value. So you don't add something by returning an array. Instead you'll have to manipulate the properties of your event
When you take a look at your RegisterElementTableAttributesEvent it contains the following property
/**
 * @var array List of registered table attributes for the element type.
 */
public $tableAttributes = [];

In order to add attributes you have to do 
Event::on(
    Element::class,
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES,
    function(craft\events\RegisterElementTableAttributesEvent $e) {
        $e->tableAttributes['foo'] = [
            'label' => "Foo"
        ];
});

It's the same for your SetElementTableAttributeHtmlEvent. It has the properties 
// Properties
// =========================================================================

/**
 * @var array|null The table attribute associated with this event.
 */
public $attribute;

/**
 * @var string|null The HTML to represent a table attribute.
 */
public $html;

You can var_dump the $event to see the current properties to get to know which structure you have to include. Usually you would do
Event::on(
    Entry::class,
    Element::EVENT_SET_TABLE_ATTRIBUTE_HTML,
    function(craft\events\SetElementTableAttributeHtmlEvent $e) {
        if($e->attribute === 'foo'){
            $e->html = 'FOOOOO';
        }
    }
);


---

