本文整理汇总了PHP中Grav\Common\Page\Page::modifyHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::modifyHeader方法的具体用法?PHP Page::modifyHeader怎么用?PHP Page::modifyHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Page\Page
的用法示例。
在下文中一共展示了Page::modifyHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addExtra
/**
* Add extra items to the shortcodes stream.
*
* @param string $group The group name to add the extra items to.
* @param any $extra The item to store.
*/
public function addExtra($group, $method, $arguments = null)
{
$header = $this->page->header();
$arguments = is_array($arguments) ? $arguments : [$arguments];
// Modify page header
$shortcodes = isset($header->shortcodes) ? $header->shortcodes : [];
$shortcodes['extra'][$group][] = [$method, $arguments];
// Temporally store Shortcode extras in page header
$this->page->modifyHeader('shortcodes', $shortcodes);
if ($this->page->id() == self::getGrav()['page']->id()) {
$object = $group != 'page' ? self::getGrav()[$group] : $page;
call_user_func_array([$object, $method], $arguments);
}
}
示例2: mergeConfig
/**
* Merge global and page configurations.
*
* @param Page $page The page to merge the configurations with the
* plugin settings.
*
* @param bool $deep Should you use deep or shallow merging
*
* @return \Grav\Common\Data\Data
*/
protected function mergeConfig(Page $page, $deep = false)
{
$class_name = $this->name;
$class_name_merged = $class_name . '.merged';
$defaults = $this->config->get('plugins.' . $class_name, array());
$header = array();
if (isset($page->header()->{$class_name_merged})) {
$merged = $page->header()->{$class_name_merged};
if (count($merged) > 0) {
return $merged;
} else {
return new Data($defaults);
}
}
// Get default plugin configurations and retrieve page header configuration
if (isset($page->header()->{$class_name})) {
if ($deep) {
$header = array_replace_recursive($defaults, $page->header()->{$class_name});
} else {
$header = array_merge($defaults, $page->header()->{$class_name});
}
} else {
$header = $defaults;
}
// Create new config object and set it on the page object so it's cached for next time
$config = new Data($header);
$page->modifyHeader($class_name_merged, $config);
// Return configurations as a new data config class
return $config;
}
示例3: mergeConfig
/**
* Merge global and page configurations.
*
* @param Page $page The page to merge the configurations with the
* plugin settings.
* @param bool $deep Should you use deep or shallow merging
* @param array $params Array of additional configuration options to
* merge with the plugin settings.
*
* @return \Grav\Common\Data\Data
*/
protected function mergeConfig(Page $page, $deep = false, $params = [])
{
$class_name = $this->name;
$class_name_merged = $class_name . '.merged';
$defaults = $this->config->get('plugins.' . $class_name, []);
$page_header = $page->header();
$header = [];
if (!isset($page_header->{$class_name_merged}) && isset($page_header->{$class_name})) {
// Get default plugin configurations and retrieve page header configuration
$config = $page_header->{$class_name};
if (is_bool($config)) {
// Overwrite enabled option with boolean value in page header
$config = ['enabled' => $config];
}
// Merge page header settings using deep or shallow merging technique
if ($deep) {
$header = array_replace_recursive($defaults, $config);
} else {
$header = array_merge($defaults, $config);
}
// Create new config object and set it on the page object so it's cached for next time
$page->modifyHeader($class_name_merged, new Data($header));
} else {
if (isset($page_header->{$class_name_merged})) {
$merged = $page_header->{$class_name_merged};
$header = $merged->toArray();
}
}
if (empty($header)) {
$header = $defaults;
}
// Merge additional parameter with configuration options
if ($deep) {
$header = array_replace_recursive($header, $params);
} else {
$header = array_merge($header, $params);
}
// Return configurations as a new data config class
return new Data($header);
}
示例4: storeFiles
/**
* @param \Grav\Common\Page\Page|\Grav\Common\Data\Data $obj
*
* @return \Grav\Common\Page\Page|\Grav\Common\Data\Data
*/
protected function storeFiles($obj)
{
// Process previously uploaded files for the current URI
// and finally store them. Everything else will get discarded
$queue = $this->admin->session()->getFlashObject('files-upload');
$queue = $queue[base64_encode($this->grav['uri']->url())];
if (is_array($queue)) {
foreach ($queue as $key => $files) {
foreach ($files as $destination => $file) {
if (!rename($file['tmp_name'], $destination)) {
throw new \RuntimeException(sprintf($this->admin->translate('PLUGIN_ADMIN.FILEUPLOAD_UNABLE_TO_MOVE', null), '"' . $file['tmp_name'] . '"', $destination));
}
unset($files[$destination]['tmp_name']);
}
if ($this->view == 'pages') {
$keys = explode('.', preg_replace('/^header./', '', $key));
$init_key = array_shift($keys);
if (count($keys) > 0) {
$new_data = isset($obj->header()->{$init_key}) ? $obj->header()->{$init_key} : [];
Utils::setDotNotation($new_data, implode('.', $keys), $files, true);
} else {
$new_data = $files;
}
if (isset($data['header'][$init_key])) {
$obj->modifyHeader($init_key, array_replace_recursive([], $data['header'][$init_key], $new_data));
} else {
$obj->modifyHeader($init_key, $new_data);
}
} else {
// TODO: [this is JS handled] if it's single file, remove existing and use set, if it's multiple, use join
$obj->join($key, $files);
// stores
}
}
}
return $obj;
}