DEPRECATED $page->modular() in favor of $page->isModule() for better readability

This commit is contained in:
Matias Griese
2019-11-15 21:15:38 +02:00
parent 571674a4f5
commit be3ecf1377
14 changed files with 58 additions and 25 deletions

View File

@@ -6,7 +6,8 @@
* Added `Utils::isAssoc()` and `Utils::isNegative()` helper methods
* Changed `UserInterface::authorize()` to return `null` having the same meaning as `false` if access is denied because of no matching rule
* Moved all Flex type classes under `Grav\Common\Flex`
* Deprecated `Grav\Common\User\Group` in favor of `$grav['user_groups']`, which contains Flex UserGroup collection
* DEPRECATED `Grav\Common\User\Group` in favor of `$grav['user_groups']`, which contains Flex UserGroup collection
* DEPRECATED `$page->modular()` in favor of `$page->isModule()` for better readability
* Fixed phpstan issues in all code up to level 3
1. [](#improved)
* Improved twig `|array` filter to work with iterators and objects with `toArray()` method
@@ -129,7 +130,7 @@
* Added a new `bin/grav server` CLI command to easily run Symfony or PHP built-in webservers
* Added `hasFlexFeature()` method to test if `FlexObject` or `FlexCollection` implements a given feature
* Added `getFlexFeatures()` method to return all features that `FlexObject` or `FlexCollection` implements
* Deprecated `FlexDirectory::update()` and `FlexDirectory::remove()`
* DEPRECATED `FlexDirectory::update()` and `FlexDirectory::remove()`
* Added `FlexStorage::getMetaData()` to get updated object meta information for listed keys
* Added `Language::getPageExtensions()` to get full list of supported page language extensions
* Added `$grav->close()` method to properly terminate the request with a response

View File

@@ -272,8 +272,12 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
public function modular()
{
$entries = [];
/**
* @var int|string $key
* @var PageInterface|null $object
*/
foreach ($this as $key => $object) {
if ($object && $object->modular()) {
if ($object && $object->isModule()) {
$entries[$key] = $object;
}
}
@@ -289,8 +293,12 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa
public function nonModular()
{
$entries = [];
/**
* @var int|string $key
* @var PageInterface|null $object
*/
foreach ($this as $key => $object) {
if ($object && !$object->modular()) {
if ($object && !$object->isModule()) {
$entries[$key] = $object;
}
}

View File

@@ -393,7 +393,7 @@ class PageIndex extends FlexPageIndex
// TODO: maybe icon by home/modular/page/folder (or even from blueprints) and color by visibility etc..
if ($child->home()) {
$icon = 'home';
} elseif ($child->modular()) {
} elseif ($child->isModule()) {
$icon = 'modular';
} elseif ($child->visible()) {
$icon = 'visible';

View File

@@ -219,7 +219,7 @@ class PageObject extends FlexPageObject
/** @var Admin|null $admin */
$admin = Grav::instance()['admin'] ?? null;
if ($admin) {
$template = $this->modular() ? 'modular_raw' : 'raw';
$template = $this->isModule() ? 'modular_raw' : 'raw';
return $admin->blueprints("admin/pages/{$template}");
}

View File

@@ -68,6 +68,6 @@ trait PageContentTrait
public function isPage(): bool
{
// FIXME: needs to be better
return !$this->exists() || !empty($this->getLanguages()) || $this->modular();
return !$this->exists() || !empty($this->getLanguages()) || $this->isModule();
}
}

View File

@@ -404,7 +404,7 @@ class Collection extends Iterator implements PageCollectionInterface
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);
if ($page !== null && $page->modular()) {
if ($page !== null && $page->isModule()) {
$modular[$path] = $slug;
}
}
@@ -424,7 +424,7 @@ class Collection extends Iterator implements PageCollectionInterface
foreach ($this->items as $path => $slug) {
$page = $this->pages->get($path);
if ($page !== null && !$page->modular()) {
if ($page !== null && !$page->isModule()) {
$modular[$path] = $slug;
}
}

View File

@@ -228,6 +228,13 @@ interface PageContentInterface
*/
public function shouldProcess($process);
/**
* Returns true if page is a module.
*
* @return bool
*/
public function isModule(): bool;
/**
* Returns whether or not this Page object has a .md file associated with it or if its just a directory.
*

View File

@@ -349,8 +349,8 @@ interface PageLegacyInterface
* Gets and sets the modular var that helps identify this page is a modular child
*
* @param bool $var true if modular_twig
*
* @return bool true if modular_twig
* @deprecated 1.7 Use ->isModule() or ->modularTwig() method instead.
*/
public function modular($var = null);
@@ -462,7 +462,6 @@ interface PageLegacyInterface
* @param string|array $value
* @param bool $only_published
* @return mixed
* @internal
*/
public function evaluate($value, $only_published = true);

View File

@@ -933,7 +933,7 @@ class Page implements PageInterface
$pattern = '%(' . preg_quote($language, '%') . ')?\.md$%';
$name = preg_replace($pattern, '', $name);
if ($this->modular()) {
if ($this->isModule()) {
return 'modular/' . $name;
}
@@ -1294,7 +1294,7 @@ class Page implements PageInterface
$this->template = $var;
}
if (empty($this->template)) {
$this->template = ($this->modular() ? 'modular/' : '') . str_replace($this->extension(), '', $this->name());
$this->template = ($this->isModule() ? 'modular/' : '') . str_replace($this->extension(), '', $this->name());
}
return $this->template;
@@ -2220,11 +2220,13 @@ class Page implements PageInterface
* Gets and sets the modular var that helps identify this page is a modular child
*
* @param bool $var true if modular_twig
*
* @return bool true if modular_twig
* @deprecated 1.7 Use ->isModule() or ->modularTwig() method instead.
*/
public function modular($var = null)
{
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use ->isModule() or ->modularTwig() method instead', E_USER_DEPRECATED);
return $this->modularTwig($var);
}
@@ -2233,7 +2235,6 @@ class Page implements PageInterface
* twig processing handled differently from a regular page.
*
* @param bool $var true if modular_twig
*
* @return bool true if modular_twig
*/
public function modularTwig($var = null)
@@ -2639,6 +2640,14 @@ class Page implements PageInterface
return !$this->isPage();
}
/**
* @return bool
*/
public function isModule(): bool
{
return $this->modularTwig();
}
/**
* Returns whether the page exists in the filesystem.
*

View File

@@ -407,7 +407,7 @@ class Pages
foreach ($params['taxonomies'] ?? [] as $taxonomy => $items) {
foreach ($collection as $page) {
// Don't filter modular pages
if ($page->modular()) {
if ($page->isModule()) {
continue;
}
@@ -1070,7 +1070,7 @@ class Pages
if ($limitLevels === false || ($level+1 < $limitLevels)) {
foreach ($current->children() as $next) {
if ($showAll || $next->routable() || ($next->modular() && $showModular)) {
if ($showAll || $next->routable() || ($next->isModule() && $showModular)) {
$list = array_merge($list, $this->getList($next, $level + 1, $rawRoutes, $showAll, $showFullpath, $showSlug, $showModular, $limitLevels));
}
}
@@ -1180,7 +1180,7 @@ class Pages
/** @var PageInterface|null $page */
$page = $admin->page();
$type = $page && $page->modular() ? 'modular' : 'standard';
$type = $page && $page->isModule() ? 'modular' : 'standard';
}
switch ($type) {

View File

@@ -165,7 +165,6 @@ class FlexDirectory implements FlexAuthorizeInterface
* @param string $type
* @param string $context
* @return Blueprint
* @internal
*/
public function getBlueprint(string $type = '', string $context = '')
{
@@ -699,7 +698,7 @@ class FlexDirectory implements FlexAuthorizeInterface
$object = $call['object'];
if ($function === '\Grav\Common\Page\Pages::pageTypes') {
$params = [$object instanceof PageInterface && $object->modular() ? 'modular' : 'standard'];
$params = [$object instanceof PageInterface && $object->isModule() ? 'modular' : 'standard'];
}
$data = null;

View File

@@ -223,7 +223,7 @@ trait PageContentTrait
'visible',
$var,
function ($value) {
return ($value ?? $this->order() !== false) && !$this->modular();
return ($value ?? $this->order() !== false) && !$this->isModule();
}
);
@@ -479,6 +479,14 @@ trait PageContentTrait
return !$this->isPage();
}
/**
* @return bool
*/
public function isModule(): bool
{
return $this->modularTwig();
}
/**
* @inheritdoc
*/
@@ -648,7 +656,7 @@ trait PageContentTrait
$config = $grav['config'];
$process_markdown = $this->shouldProcess('markdown');
$process_twig = $this->shouldProcess('twig') || $this->modularTwig();
$process_twig = $this->shouldProcess('twig') || $this->isModule();
$cache_enable = $this->getNestedProperty('header.cache_enable') ?? $config->get('system.cache.enabled', true);
$twig_first = $this->getNestedProperty('header.twig_first') ?? $config->get('system.pages.twig_first', true);

View File

@@ -477,7 +477,7 @@ trait PageLegacyTrait
'template',
$var,
function ($value) {
return trim($value ?? (($this->modular() ? 'modular/' : '') . str_replace($this->extension(), '', $this->name())));
return trim($value ?? (($this->isModule() ? 'modular/' : '') . str_replace($this->extension(), '', $this->name())));
}
);
}
@@ -807,11 +807,13 @@ trait PageLegacyTrait
* Gets and sets the modular var that helps identify this page is a modular child
*
* @param bool $var true if modular_twig
*
* @return bool true if modular_twig
* @deprecated 1.7 Use ->isModule() or ->modularTwig() method instead.
*/
public function modular($var = null): bool
{
user_error(__METHOD__ . '() is deprecated since Grav 1.7, use ->isModule() or ->modularTwig() method instead', E_USER_DEPRECATED);
return $this->modularTwig($var);
}

View File

@@ -61,7 +61,7 @@ trait PageRoutableTrait
}
);
return $value && $this->published() && !$this->modular() && $this->getLanguages(true);
return $value && $this->published() && !$this->isModule() && $this->getLanguages(true);
}
/**