Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pontedilana/open-graph-bundle
https://github.com/pontedilana/open-graph-bundle
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pontedilana/open-graph-bundle
- Owner: pontedilana
- License: mit
- Created: 2023-03-03T15:26:19.000Z (almost 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-06T14:42:09.000Z (about 2 months ago)
- Last Synced: 2024-11-06T15:39:21.059Z (about 2 months ago)
- Language: PHP
- Size: 98.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![PHP Version](https://img.shields.io/packagist/php-v/pontedilana/open-graph-bundle.svg)](https://packagist.org/packages/pontedilana/open-graph-bundle)
[![Latest Stable Version](https://img.shields.io/packagist/v/pontedilana/open-graph-bundle.svg?label=stable)](https://packagist.org/packages/pontedilana/open-graph-bundle)
[![Total Downloads](https://img.shields.io/packagist/dt/pontedilana/open-graph-bundle.svg)](https://packagist.org/packages/pontedilana/open-graph-bundle)
[![Total Downloads](https://img.shields.io/packagist/dm/pontedilana/open-graph-bundle.svg)](https://packagist.org/packages/pontedilana/open-graph-bundle)
[![License](https://img.shields.io/packagist/l/pontedilana/open-graph-bundle.svg)](https://packagist.org/packages/pontedilana/open-graph-bundle)# OpenGraphBundle
The PontedilanaOpenGraphBundle is a simple way to improve how you manage OpenGraph
into your Symfony application, through the use of the [euskadi31/opengraph](https://github.com/euskadi31/opengraph) library.This repository is a fork of [tenolo/open-graph-bundle](https://github.com/tenolo/open-graph-bundle) maintained
by [Pontedilana](https://www.pontedilana.it); support for PHP 8, Symfony 5 and 6 as been added.> **Note**: OpenGraph is a standard protocol used by many websites (Facebook,
> Twitter, Google, ...) to obtain more precise information about your content.
>
> [Learn more about OpenGraph](https://ogp.me/)The idea of this bundle it to associate each entity of your app with an **OpenGraph map**, a service
able to create the OpenGraph document for your entity.It also works with any other type of data.
## Installation
Installation is very quick:
### 1. Download it with Composer
Add the bundle to your `composer.json` file by running:
`composer require pontedilana/open-graph-bundle`
### 2. Enable it in your kernel
Enable the bundle in your `app/AppKernel.php` file;
```php
append(OpenGraph::OG_SITE_NAME, 'MyBlog');
$document->append(OpenGraph::OG_TYPE, OpenGraph::TYPE_ARTICLE);
$document->append(OpenGraph::OG_TITLE, $data->getTitle());
}public function supports($data)
{
return $entity instanceof BlogPost;
}
}
```The `supports` method declares with what kind of entities this map is able to deal.
The `map` method create an OpenGraph document representing the given entity.Once created, we still have to register our class into the OpenGraph manager. To do so,
we will have to use the tag `pontedilana_open_graph.map`:``` yml
services:
App\OpenGraph\:
resource: '../src/OpenGraph'
tags: [ 'pontedilana_open_graph.map' ]
```### Using the map
Our map is registered, so we can use it anywhere we want to render it.
For instance, with Twig:``` html
Blog post{{ opengraph_render(blogPost) }}
...
```
> **Note**: if no map is able to deal with the entity given in `opengraph_render`,
> an `NotSupported` exception will be thrown.> **Another Note**: Credits and inspiration goes to [tgalopin](https://github.com/tgalopin/OpenGraphBundle)