/**
  * Checks if a given field is correctly filled.
  *
  * @param	Fields\AbstractField	$field	The field.
  * @return	array							An array with 2 indexes:
  * 											 - fieldLabel:			The translated label of the field.
  * 											 - validationResult:	List of TYPO3\CMS\Extbase\Error\Result
  */
 public function validateField(Fields\AbstractField $field)
 {
     $fieldValidation = array('fieldLabel' => Core::translate($field->getLabel()));
     $validationResult = $field->validate()->getValidationResult();
     $fieldValidation['validationResult'] = $validationResult;
     return $fieldValidation;
 }
 /**
  * Gets an ordered list of the backend layouts.
  *
  * @return	array	The backend layouts in an array. Empty array if none was found.
  */
 public static function getBackendLayoutsList()
 {
     /** @var \TYPO3\CMS\Backend\View\BackendLayoutView $backendLayoutView */
     $backendLayoutView = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\BackendLayoutView');
     $items = array();
     $params = array('table' => 'pages', 'field' => 'backend_layout', 'row' => BackendUtility::getRecord('pages', 1, '*'), 'items' => &$items);
     $backendLayoutView->addBackendLayoutItems($params);
     $result = array();
     foreach ($GLOBALS['TCA']['pages']['columns']['backend_layout']['config']['items'] as $item) {
         $result[$item[1]] = Core::translate($item[0]);
     }
     foreach ($params['items'] as $item) {
         $result[$item[1]] = $item[0];
     }
     return $result;
 }
 /**
  * @todo: rewrite function doc
  * @param string $cacheToken The token of the cache file to get the current state of the duplication.
  * @param string $index      The index of the process which will be executed (e.g. "pagesDuplication" or "treeUidAssociation").
  * @param bool   $checkAjax  If true, will call the function "checkAjaxCall" of the current process class.
  * @return    array The result of the function, may contain these keys :
  *                           - "success":      "False" if error(s) occurred, "true" otherwise.
  *                           - "result":       The result of the execution function. Contains useful data for further duplication process steps.
  *                           - "errorMessage": If error(s) occurred, will contain an error message. If the current user is admin, it will get a detailed message.
  */
 private function processDuplication($cacheToken, $index, $checkAjax = false)
 {
     // Getting configuration in cache file.
     $cache = CacheManager::getCacheInstance(CacheManager::CACHE_PROCESSED);
     $cacheData = $cache->get($cacheToken);
     $cacheData = json_decode($cacheData, true);
     /** @var Result $result */
     $result = $this->objectManager->get(Result::class);
     try {
         if (isset($cacheData['duplicationData']['modelPageUid']) && MathUtility::canBeInterpretedAsInteger($cacheData['duplicationData']['modelPageUid']) && $cacheData['duplicationData']['modelPageUid'] > 0) {
             $duplicationConfiguration = AbstractDuplicationProcess::getCleanedDuplicationConfiguration($cacheData['duplicationData']['modelPageUid']);
             if (isset($duplicationConfiguration[$index])) {
                 if (isset($duplicationConfiguration[$index]['class'])) {
                     $class = $duplicationConfiguration[$index]['class'];
                     $settings = array_key_exists('settings', $duplicationConfiguration[$index]) ? is_array($duplicationConfiguration[$index]['settings']) ? $duplicationConfiguration[$index]['settings'] : [] : [];
                     // Calling the function of the current process step.
                     /** @var AbstractDuplicationProcess $class */
                     $class = GeneralUtility::makeInstance($class, $cacheData['duplicationData'], $settings, $cacheData['fieldsValues']);
                     if ($class instanceof AbstractDuplicationProcess) {
                         // @todo : else
                         //                            if (!$checkAjax || ($checkAjax && $class->checkAjaxCall())) {
                         $class->run();
                         $fieldsValues = $class->getFieldsValues();
                         $result->merge($class->getResult());
                         // Saving modified data in cache.
                         $configuration = ['duplicationData' => $class->getDuplicationData(), 'fieldsValues' => $fieldsValues];
                         $cache->set($cacheToken, json_encode($configuration));
                         //                            }
                     } else {
                         throw new \Exception('The class "' . $class . '" must extend "' . AbstractDuplicationProcess::class . '".', 1422887215);
                     }
                 } else {
                     throw new \Exception('The class is not set for the duplication configuration named "' . $index . '".', 1422885526);
                 }
             } else {
                 throw new \Exception('Trying to get the duplication configuration named "' . $index . '" but it does not exist.', 1422885438);
             }
         } else {
             throw new \Exception('The duplication data must contain a valid index for "modelPageUid".', 1422885697);
         }
     } catch (\Exception $exception) {
         /** @var BackendUserAuthentication $backendUser */
         $backendUser = $GLOBALS['BE_USER'];
         // Setting up error message. If the user is admin, it gets a detailed message.
         if ($backendUser->isAdmin()) {
             $errorMessage = Core::translate('duplication_process.process_error_detailed') . ' ' . $exception->getMessage();
         } else {
             $errorMessage = Core::translate('duplication_process.process_error_single');
         }
         $result->addError(new Error($errorMessage, 1431985617));
     }
     return Core::convertValidationResultToArray($result);
 }
 /**
  * Adds a message (error, warning or notice) to the process result.
  *
  * @param	string	$type		The type of the message. Can only be one of the following: error, warning or notice.
  * @param	string	$message	The message, can be a locallang reference.
  * @param	int		$code		A unique code for this notice.
  * @param	array	$arguments	Array of arguments to be replaced in the message.
  * @param	string	$title		The title for the message.
  */
 private function addMessage($type, $message, $code, array $arguments = array(), $title = '')
 {
     if (!in_array(strtolower($type), array('error', 'warning', 'notice'))) {
         return;
     }
     $function = 'add' . ucfirst($type);
     $type = 'TYPO3\\CMS\\Extbase\\Error\\' . ucfirst($type);
     $this->result->{$function}(new $type(Core::translate($message), $code, $arguments, $title));
 }
 /**
  * Sets the hint of the field.
  *
  * @param string $hint
  * @return $this
  */
 public function setHint($hint)
 {
     $this->hint = Core::translate((string) $hint);
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Sets the placeholder of the field.
  *
  * @param string $placeholder
  * @return $this
  */
 public function setPlaceholder($placeholder)
 {
     $this->placeholder = Core::translate((string) $placeholder);
     return $this;
 }