/**
	 * Auxiliary function for replacing texts when extending XML
	 * <replaces translate="yes"><replace attribute="label OR [DATA]" from="{source}" to="target" />
	 *
	 * @param  SimpleXMLElement|string|array $sourceData             Source data to substitute
	 * @param  SimpleXMLElement|null         $sourceNode             (unused)
	 * @param  SimpleXMLElement|null         $destinationParentNode  (unused)
	 * @param  RegistryEditView                   $paramsView             The params view to access data to replace if attribute type="datavalue:string"
	 * @return string|string[]|SimpleXMLElement|null                 The replaced $sourceData
	 */
	static function _substituteChildTexts( $sourceData, /** @noinspection PhpUnusedParameterInspection */ $sourceNode = null, /** @noinspection PhpUnusedParameterInspection */ $destinationParentNode = null, $paramsView = null ) {
		static $substitutions	=	array();
		if ( is_array( $sourceData ) ) {
			// that is $source->attributes():
			$return				=	array();
			foreach ($sourceData as $k => $v ) {
				if ( isset( $substitutions[$k] ) ) {
					$v			=	str_replace( $substitutions[$k]['from'], $substitutions[$k]['to'], $v );
					if ( $substitutions[$k]['translate'] ) {
						$v		=	CBTxt::T( $v );
					}
				}
				$return[$k]		=	$v;
			}
		} elseif ( is_string( $sourceData ) ) {
			// that is $source->data():
			if ( isset( $substitutions['[DATA]'] ) ) {
				$k				=	'[DATA]';
				$return			=	str_replace( $substitutions[$k]['from'], $substitutions[$k]['to'], $sourceData );
				if ( $substitutions[$k]['translate'] ) {
					$return		=	CBTxt::T( $return );
				}
			} else {
				$return			=	$sourceData;
			}
		} elseif ( is_object( $sourceData ) ) {
			// initialize replacements:
			$substitutions		=	array();
			foreach ($sourceData->children() as $replaceRule ) {
				/** @var $replaceRule SimpleXMLElement */
				$substitutions[$replaceRule->attributes( 'attribute' )]['from'][]			=	$replaceRule->attributes( 'from' );
				$substitutions[$replaceRule->attributes( 'attribute' )]['to'][]				=	( $replaceRule->attributes( 'type' ) == 'datavalue:string' ? $paramsView->get( $replaceRule->attributes( 'to' ) ) : $replaceRule->attributes( 'to' ) );
				$substitutions[$replaceRule->attributes( 'attribute' )]['translate']		=	$replaceRule->attributes( 'translate' ) === 'yes';
			}
			$return				=	null;
		} else {
			trigger_error(__CLASS__ . '::' . __FUNCTION__ . 'Invalid type for $sourceData.' );
			$return				=	null;
		}
		return $return;
	}
Example #2
0
 /**
  * Gets the data from the model for a field $key
  * @param  string  $key      The name of the field
  * @param  mixed   $default  The default value if not found
  * @return string
  */
 public function get($key, $default = null)
 {
     return $this->registryEditView->get($key, $default);
 }