Skip to content

Commit

Permalink
added twitter_card_type option
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 31, 2016
1 parent 8272671 commit 093037b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ $card->addMeta('author', '@the_author'); //<meta property="twitter:author" conte
* twitterCard
* schema

### Options

The `SocialLinks\Page` accepts an array of options as the second argument. The available options are:

Name | Type | Description | Default
------------|----------|-------------|---------
twitter_card_type | `string` | The [type of card](https://dev.twitter.com/cards/types). It can be `summary`, `summary_large_image`, `app` or `player` | `"summary"`

Example:

```php
$info = [
'url' => 'http://mypage.com',
'title' => 'Page title',
'text' => 'Extended page description',
'image' => 'http://mypage.com/image.png',
'twitterUser' => '@twitterUser'
];

$page = new Page($info, [
'twitter_card_type' => 'summary_large_image'
]);
```

## Usage in Symfony

Expand Down
2 changes: 1 addition & 1 deletion src/Metas/Twittercard.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Twittercard extends MetaBase implements MetaInterface
*/
protected function generateTags()
{
$this->addMeta('card', 'summary');
$this->addMeta('card', $this->page->getConfig('twitter_card_type', 'summary'));

$this->addMetas($this->page->get(array(
'title',
Expand Down
13 changes: 5 additions & 8 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,13 @@ public function get(array $info = null)
/**
* Gets one or all configuration option.
*
* @param string|null $name
* @param string $name
* @param null $default
*
* @return string|array|null
* @return mixed
*/
public function getConfig($name = null)
public function getConfig($name, $default = null)
{
if ($name === null) {
return $this->config;
}

return isset($this->config[$name]) ? $this->config[$name] : null;
return isset($this->config[$name]) ? $this->config[$name] : $default;
}
}
19 changes: 19 additions & 0 deletions tests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,23 @@ public function testMetas(Page $page)
$this->assertEquals($html, '<meta name="title" content="Page title"><meta name="description" content="Extended page description &amp;"><link rel="image_src" href="http://mypage.com/image.png"><link rel="canonical" href="http://mypage.com">');
$this->assertEquals($schema, '<meta itemprop="name" content="Page title"><meta itemprop="description" content="Extended page description &amp;"><meta itemprop="image" content="http://mypage.com/image.png">');
}

public function testOptions()
{
$info = array(
'url' => 'http://example.com',
'title' => 'Title',
'text' => 'Description',
'image' => 'http://example.com/image.png',
'twitterUser' => '@example',
);

$page = new Page($info, array(
'twitter_card_type' => 'summary_large_image'
));

$twitterCard = $page->twitterCard();

$this->assertEquals('<meta name="twitter:card" content="summary_large_image">', $twitterCard['card']);
}
}

0 comments on commit 093037b

Please sign in to comment.