-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: autoprepend causing wrong options field values
- Loading branch information
1 parent
6efdf9d
commit 27f9a04
Showing
1 changed file
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
<?php namespace ProcessWire; | ||
<?php | ||
|
||
namespace ProcessWire; | ||
|
||
/** | ||
* This file is automatically added to the prependFile array. | ||
* If you are using /site/templates/_init.php this file ensures that all defined | ||
* variables and functions are available from every file that is rendered via | ||
* RockFrontend. | ||
*/ | ||
if($rockfrontend->autoprepended) return; | ||
$vars = array_merge(get_defined_vars(), (array)$this->wire('all')); | ||
foreach($vars as $k=>$v) $this->wire($k, $v); | ||
if ($rockfrontend->autoprepended) return; | ||
|
||
// this fixes the issue that $page->any_options_field->title | ||
// shows the page title instead of the options' value title | ||
// see https://processwire.com/talk/topic/29225-show-this-field-only-if-doesnt-seem-to-work/?do=findComment&comment=237096 | ||
$vars = get_defined_vars(); | ||
foreach ($page->getFields() as $field) { | ||
if (!array_key_exists($field->name, $vars)) continue; | ||
unset($vars[$field->name]); | ||
} | ||
|
||
// merge arrays and make them available as API variable | ||
$vars = array_merge($vars, (array)$this->wire('all')); | ||
foreach ($vars as $k => $v) { | ||
$this->wire($k, $v); | ||
} | ||
|
||
$rockfrontend->autoprepended = true; |