<?php
namespace SabaiApps\Directories\Component\Display\Controller\Admin;

use SabaiApps\Directories\Context;
use SabaiApps\Directories\Component\Form;

class ExportElement extends Form\Controller {

	protected function _doGetFormSettings( Context $context, array &$storage ) {
		$this->_submitable = false;

		if ( ( ! $element_id = $context->getRequest()->asStr( 'element_id' ) )
			|| ( ! $element = $this->getModel( 'Element', 'Display' )->fetchById( $element_id ) )
			|| $element->display_id !== $context->display->id
		) {
			$context->setError();
			return;
		}

		return array(
			'data' => array(
				'#type'       => 'textarea',
				'#attributes' => array(
					'readonly' => 'readonly',
					'onclick'  => 'this.select();',
				),
				'#value'      => $this->System_Util_jsonEncode( $this->Display_AdminElement_exportElements( new \ArrayIterator( array( $element ) ) ) ),
			),
		);
	}
}
