<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\AssetBundle\EventListener;
use Pimcore\Event\AdminEvents;
use Pimcore\Event\Model\GenericEvent;
/**
* Description of AssetTreePreSendData
*
* @author nehachugh
*/
class AssetTreePreSendData {
public function changeData($event) {
$assets = $event->getArgument("assets");
if (is_array($assets)) {
foreach ($assets as $key => $assetData) {
$asset = \Pimcore\Model\Asset::getById($assetData["id"]);
if ($asset && ($asset instanceof \Pimcore\Model\Asset\Image || $asset instanceof \Pimcore\Model\Asset\Document)) {
if (trim($asset->getProperty("active")) != "Active") {
$assetData["cls"] = $assetData["cls"] . " pimcore_unpublished";
$assetData["published"] = FALSE;
} else {
$assetData["published"] = TRUE;
}
$assets [$key] = $assetData;
}
}
$event->setArgument("assets", $assets);
}
}
public function changeAssetData($event) {
$data = $event->getArgument("data");
$asset = \Pimcore\Model\Asset::getById($data["id"]);
if ($asset && ($asset instanceof \Pimcore\Model\Asset\Image || $asset instanceof \Pimcore\Model\Asset\Document)) {
if (trim($asset->getProperty("active")) != "Active") {
$data["published"] = FALSE;
} else {
$data["published"] = TRUE;
}
$event->setArgument("data", $data);
}
}
}