Skip to content

Instantly share code, notes, and snippets.

@johndwells
Last active June 12, 2017 05:28
Show Gist options
  • Save johndwells/cd17ef8f565d38a2aea1 to your computer and use it in GitHub Desktop.
Save johndwells/cd17ef8f565d38a2aea1 to your computer and use it in GitHub Desktop.
Simple plugin to modify the asset's table view in Craft CMS
<?php
namespace Craft;
class AssetTableModsPlugin extends BasePlugin
{
public function getName()
{
return 'Asset Table Modifications';
}
public function getVersion()
{
return '0.1.0';
}
public function getDeveloper()
{
return 'John D Wells';
}
public function getDeveloperUrl()
{
return 'http://onedarnleyroad.com';
}
public function hasCpSection()
{
return false;
}
public function modifyAssetTableAttributes(&$attributes, $source)
{
// Add width & height columns
$attributes['width'] = Craft::t('Width');
$attributes['height'] = Craft::t('Height');
}
public function getAssetTableAttributeHtml(AssetFileModel $asset, $attribute)
{
// Add width value
if ($attribute == 'width' && $asset->width)
{
return $asset->width . 'px';
}
// Add height value
if ($attribute == 'height' && $asset->height)
{
return $asset->height . 'px';
}
// Link the asset's filename to the original file
if ($attribute == 'filename')
{
return '<a href="' . $asset->getUrl() . '" target="_blank" class="go">' . $asset->filename . '</a>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment