replaceVariable example


  protected function replaceName($name$data) {
    if (preg_match_all("/\[(.*)\]/U", $name$matches)) {
      // Build our list of '[value]' => replacement.       $replace = [];
      foreach (array_combine($matches[0]$matches[1]) as $key => $value) {
        $replace[$key] = $this->replaceVariable($value$data);
      }
      return strtr($name$replace);
    }
    else {
      return $name;
    }
  }

  /** * Replaces variable values in included names with configuration data. * * Variable values are nested configuration keys that will be replaced by * their value or some of these special strings: * - '%key', will be replaced by the element's key. * - '%parent', to reference the parent element. * - '%type', to reference the schema definition type. Can only be used in * combination with %parent. * * There may be nested configuration keys separated by dots or more complex * patterns like '%parent.name' which references the 'name' value of the * parent element. * * Example patterns: * - 'name.subkey', indicates a nested value of the current element. * - '%parent.name', will be replaced by the 'name' value of the parent. * - '%parent.%key', will be replaced by the parent element's key. * - '%parent.%type', will be replaced by the schema type of the parent. * - '%parent.%parent.%type', will be replaced by the schema type of the * parent's parent. * * @param string $value * Variable value to be replaced. * @param mixed $data * Configuration data for the element. * * @return string * The replaced value if a replacement found or the original value if not. */
Home | Imprint | This part of the site doesn't use cookies.