<p>You should <strong>never</strong> edit the core files (i.e. anything below /app), because whatever changes you add might be overwritten any time Craft is updated – or even worse, your amendments might conflict with new features added in Craft updates to a different part of the codebase; crashing your entire site. Seriously, don't do it.</p>

<p>Whenever you need Craft to do something that it doesn't do out of the box, your options are:</p>

<p>– Installing an off-the-shelf plugin, of which <a href="https://straightupcraft.com/craft-plugins" rel="nofollow noreferrer">there are many</a><br>
– <a href="https://pluginfactory.io/" rel="nofollow noreferrer">Writing a plugin yourself</a> (which <a href="https://craftcms.com/docs/plugins/introduction" rel="nofollow noreferrer">shouldn't be too hard</a>, if you have PHP experience)<br>
– <a href="https://straightupcraft.com/jobs" rel="nofollow noreferrer">Finding</a> <a href="https://craftcms.com/community" rel="nofollow noreferrer">someone</a> <a href="https://www.workwithcraft.com/" rel="nofollow noreferrer">else</a> to build your custom plugin<br>
– <a href="https://craftcms.uservoice.com/forums/285221-feature-requests" rel="nofollow noreferrer">Adding a feature request</a>  </p>

<p>If you do need to write a custom plugin, probably the most important thing to know about are <a href="https://craftcms.com/docs/plugins/hooks-and-events" rel="nofollow noreferrer"><em>hooks and events</em></a>, which offer ways to hook into and act upon various parts of the Craft internals and request lifecycle.</p>

<p>Specifically, <em>I believe your current use case could be easily solved by creating a small custom plugin</em> with the <a href="https://craftcms.com/docs/plugins/hooks-reference#defineAdditionalEntryTableAttributes" rel="nofollow noreferrer"><code>defineAdditionalEntryTableAttributes</code></a> hook.</p>

<p>Here's how that could look, assuming your custom property is named <code>customProperty</code> (the following would go into your plugin's primary class, e.g. <code>myplugin/MyPluginPlugin.php</code>):</p>

<pre><code>public function defineAdditionalEntryTableAttributes()
{
    return array(
        'customProperty' =&gt; "Custom label",
    );
}
</code></pre>

<p>With the above, you'll be able to simply add your custom property to the relevant element indexes via the little cogwheel below your Sections, under Entries inside the CP.</p>

<p>If you need more control over how the custom property renders (for instance, if the property returns a non-String value, you want to wrap the property value in some HTML, or you need to account for the custom property not being set for all entries, etc), you can use the <a href="https://craftcms.com/docs/plugins/hooks-reference#getEntryTableAttributeHtml" rel="nofollow noreferrer"><code>getEntryTableAttributeHtml</code></a> hook to refine things:</p>

<pre><code>public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
{
    if ($attribute == 'customProperty' &amp;&amp; isset($entry-&gt;customProperty))
    {
        return '&lt;span class="some-class-name"&gt;'.$entry-&gt;customProperty[0].'&lt;/span&gt;';
    }
}
</code></pre>

CC BY-SA 3.0
2017-01-03T15:14:51.290Z
Many thanks for the detailed answer! I will take a look into the resources you've advised.
Chris
CC BY-SA 3.0
2017-01-03T13:40:43.343Z
2017-01-03T21:36:01.933Z
2017-01-03T21:36:01.933Z
Mats Mikkel Rummelhoff
<p>I've been tasked with adding a column to the Entries screen to show some custom data that gets saved against each new post. To do this, I've edited <code>craft/app/elementtypes/EntryElementType.php</code> and added a new table attribute, which does what I need and shows the column.*</p>

<p>However, I'm wary though that updating Craft involves removing the <code>/app</code> directory and replacing it with the one from the latest release.</p>

<p>Is there an advised way I should make tweaks to core files like the one I mentioned? Or, is the only solution to do something like...</p>

<ul>
<li>Add PHP comments around any core code I tweak</li>
<li>When preparing for an update, compare the old <code>/app</code> against the new one in GitHub</li>
<li>From there, search through the changes to find the comments I've added</li>
<li>For each comment I find, I should manually recreate the changes in the correct places within the new version of <code>/app</code></li>
</ul>

<hr>

<p>* Just to clarify, I was using an older version of Craft when I wrote this post. Having updated to 2.6, I now see that choosing which columns to show on the Entries screen is a baked-in feature. Nice :)</p>

<extends><editing>
The safest way to edit core Craft files?
# The safest way to edit core Craft files?

(Asked by: username_0 on 2017-01-03)

I've been tasked with adding a column to the Entries screen to show some custom data that gets saved against each new post. To do this, I've edited `craft/app/elementtypes/EntryElementType.php` and added a new table attribute, which does what I need and shows the column.\*

However, I'm wary though that updating Craft involves removing the `/app` directory and replacing it with the one from the latest release.

Is there an advised way I should make tweaks to core files like the one I mentioned? Or, is the only solution to do something like...

* Add PHP comments around any core code I tweak
* When preparing for an update, compare the old `/app` against the new one in GitHub
* From there, search through the changes to find the comments I've added
* For each comment I find, I should manually recreate the changes in the correct places within the new version of `/app`

---

\* Just to clarify, I was using an older version of Craft when I wrote this post. Having updated to 2.6, I now see that choosing which columns to show on the Entries screen is a baked-in feature. Nice :)

**Tags:** extends, editing


---

## 1 answers

### Answer by username_1 on 2017-01-03. Score: 11 | Accepted answer

You should never edit the core files (i.e. anything below /app), because whatever changes you add might be overwritten any time Craft is updated – or even worse, your amendments might conflict with new features added in Craft updates to a different part of the codebase; crashing your entire site. Seriously, don't do it.
Whenever you need Craft to do something that it doesn't do out of the box, your options are:
– Installing an off-the-shelf plugin, of which there are many
– Writing a plugin yourself (which shouldn't be too hard, if you have PHP experience)
– Finding someone else to build your custom plugin
– Adding a feature request 
If you do need to write a custom plugin, probably the most important thing to know about are hooks and events, which offer ways to hook into and act upon various parts of the Craft internals and request lifecycle.
Specifically, I believe your current use case could be easily solved by creating a small custom plugin with the defineAdditionalEntryTableAttributes hook.
Here's how that could look, assuming your custom property is named customProperty (the following would go into your plugin's primary class, e.g. myplugin/MyPluginPlugin.php):
public function defineAdditionalEntryTableAttributes()
{
    return array(
        'customProperty' => "Custom label",
    );
}

With the above, you'll be able to simply add your custom property to the relevant element indexes via the little cogwheel below your Sections, under Entries inside the CP.
If you need more control over how the custom property renders (for instance, if the property returns a non-String value, you want to wrap the property value in some HTML, or you need to account for the custom property not being set for all entries, etc), you can use the getEntryTableAttributeHtml hook to refine things:
public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
{
    if ($attribute == 'customProperty' && isset($entry->customProperty))
    {
        return ''.$entry->customProperty[0].'';
    }
}

> **Comments:**
> **username_0**: Many thanks for the detailed answer! I will take a look into the resources you've advised.  

---

