Project

General

Profile

Feature #62436 » AbstractFormFieldViewHelper_getPropertyValue.php

Andreas Sommer, 2014-10-24 00:47

 
<?php
namespace TYPO3\CMS\Fluid\ViewHelpers\Form;

/* *
* This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* Abstract Form View Helper. Bundles functionality related to direct property access of objects in other Form ViewHelpers.
*
* If you set the "property" attribute to the name of the property to resolve from the object, this class will
* automatically set the name and value of a form element.
*
* @api
*/
abstract class AbstractFormFieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper {
/**
* Get the current property of the object bound to this form.
*
* @return mixed Value
*/
protected function getPropertyValue() {
if (!$this->viewHelperVariableContainer->exists('TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper', 'formObject')) {
return NULL;
}
$formObject = $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formObject');
$propertyName = $this->arguments['property'];
if (is_array($formObject)) {
return isset($formObject[$propertyName]) ? $formObject[$propertyName] : NULL;
}
// if the formobject has mm related checkbox fields then the propertyName is written like this "fieldname.uid"
if(!preg_match('/\.\d/', $propertyName))
{
// genreate the getFunctionName
$fn = 'get' . ucfirst($propertyName);
// only objects are needed
if(is_object($formObject->$fn()))
{
$checkedCollection = array();
// loop stored relations
foreach($formObject->$fn() as $_ => $child)
{
// prevent object errors on empy values
if(is_object($child))
{
// push uid's to the collection
$checkedCollection[] = $child->getUid();
}
}
return $checkedCollection;
}
}
return \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($formObject, $propertyName);
}
}
?>
(2-2/2)