Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from spiral-modules/request.meta
Browse files Browse the repository at this point in the history
Update MetaRequest.php
  • Loading branch information
vvval authored Jul 18, 2017
2 parents 6b0a9ee + 285e1b1 commit 0eb7370
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion source/Pages/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(PageSource $source)
/**
* @param string $uri
* @param bool $activeOnly
*
* @return null|Page
*/
public function find(string $uri, bool $activeOnly = true)
Expand All @@ -39,6 +40,7 @@ public function find(string $uri, bool $activeOnly = true)
/**
* @param Page $page
* @param array $defaults
*
* @return array
*/
public function getMeta(Page $page, array $defaults): array
Expand All @@ -47,14 +49,15 @@ public function getMeta(Page $page, array $defaults): array
'title' => $page->title,
'keywords' => $page->keywords ?: $this->defaults($defaults, 'keywords'),
'description' => $page->description ?: $this->defaults($defaults, 'description'),
'metaTags' => $page->metaTags ?: $this->defaults($defaults, 'metaTags')
'html' => $page->metaTags ?: $this->defaults($defaults, 'html')
];
}

/**
* @param array $defaults
* @param string $field
* @param string $default
*
* @return string
*/
protected function defaults(array $defaults, string $field, string $default = ''): string
Expand Down
4 changes: 2 additions & 2 deletions source/Pages/Requests/Api/MetaRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MetaRequest extends RequestFilter implements PageRequestInterface
'title' => 'data:title',
'description' => 'data:description',
'keywords' => 'data:keywords',
'metaTags' => 'data:metaTags',
'metaTags' => 'data:html',
];

/**
Expand All @@ -50,4 +50,4 @@ class MetaRequest extends RequestFilter implements PageRequestInterface
'description' => 'trim',
'metaTags' => 'trim',
];
}
}
8 changes: 4 additions & 4 deletions source/views/cms/meta.dark.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
$meta = $pages->getMeta($page, [
'description' => $page_metadata_description,
'keywords' => $page_metadata_keywords,
'metaTags' => $page_metadata_metaTags
'html' => $page_metadata_metaTags
]);

if (!empty($meta['metaTags'])) {
echo $meta['metaTags'];
if (!empty($meta['html'])) {
echo $meta['html'];
} ?>

<title><?= e($meta['title']) ?></title>
Expand All @@ -34,4 +34,4 @@
<script>
window.metadata = <?= json_encode($meta) ?>;
</script>
<?php } #compile ?>
<?php } #compile ?>
8 changes: 4 additions & 4 deletions tests/Pages/PagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function testGetMeta()
$meta = $pages->getMeta($page, [
'keywords' => 'some keywords',
'description' => 'some description',
'metaTags' => 'some metaTags',
'html' => 'some metaTags',
]);
$this->assertEmpty($meta['title']);
$this->assertSame($meta['keywords'], 'some keywords');
$this->assertSame($meta['description'], 'some description');
$this->assertSame($meta['metaTags'], 'some metaTags');
$this->assertSame($meta['html'], 'some metaTags');

$page->title = 'title';
$page->keywords = 'keywords';
Expand All @@ -83,11 +83,11 @@ public function testGetMeta()
$meta = $pages->getMeta($page, [
'keywords' => 'some keywords',
'description' => 'some description',
'metaTags' => 'some metaTags',
'html' => 'some metaTags',
]);
$this->assertSame($meta['title'], 'title');
$this->assertSame($meta['keywords'], 'keywords');
$this->assertSame($meta['description'], 'description');
$this->assertSame($meta['metaTags'], 'metaTags');
$this->assertSame($meta['html'], 'metaTags');
}
}

0 comments on commit 0eb7370

Please sign in to comment.