View file Upload/src/addons/Brivium/CustomNodeIcon/XF/Admin/Controller/Node.php

File size: 1.81Kb
<?php
namespace Brivium\CustomNodeIcon\XF\Admin\Controller;

use XF\Mvc\ParameterBag;

class Node extends XFCP_Node
{

	public function actionIcons(ParameterBag $params)
	{
        $node = $this->assertNodeExists($params->node_id);
        if (!$node->NodeType)
        {
            return $this->error(\XF::phrase('node_type_for_node_not_found_not_modifiable'), 404);
        }
        if($this->isPost())
        {

            $inputIconData = $this->filter('node_icon_data', 'array');
            $update = false;

            $iconService = $this->service('Brivium\CustomNodeIcon:Node\Icon', $node);
            foreach ($inputIconData as $typeIcon => $data)
            {
                if(empty($data['type']) || $data['type'] != 'image')
                {
                    continue;
                }

                $imageIcon = $this->request->getFile($typeIcon.'_icon', false, false);
                if($imageIcon)
                {
                    if (!$iconService->setIcon($imageIcon, $typeIcon == 'unread'))
                    {
                        return $this->error($iconService->getError());
                    }

                    $update = true;
                }
            }

            if($update)
            {
                if (!$iconService->updateIcons($inputIconData))
                {
                    return $this->error(\XF::phrase('brcni_new_icon_could_not_be_processed'));
                }
            }


            $node->setNodeIconData($inputIconData);
            $node->save();
            return $this->redirect($this->buildLink('nodes'));
        }
        
        $viewParams = [
            'node' => $node,
        ];
        return $this->view('Brivium\CustomNodeIcon:Node\Icon', 'brcni_icon_edit', $viewParams);
	}
}