Created
November 8, 2017 13:47
-
-
Save flocondetoile/8d3b6ebf11eabe6695683061151ce0e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace Drupal\arthrolink_static_blocks\Plugin\Block; | |
use Drupal\Core\Url; | |
use Drupal\arthrolink_static_blocks\StaticBlock; | |
/** | |
* Bloc statique d'exemple. | |
* | |
* @Block( | |
* id = "example_static", | |
* admin_label = @Translation("Bloc statique d'exemple"), | |
* ) | |
*/ | |
class ExampleStaticBlock extends StaticBlock { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function build() { | |
return [ | |
'#theme' => 'example_static_block', | |
'#text' => $this->t('Longtemps, je me suis couché de bonne heure et la langue courante est @langue', ['@langue' => $this->language]), | |
'#image' => [ | |
'#theme' => 'image', | |
'#uri' => drupal_get_path('module', 'arthrolink_static_blocks') . '/images/example.jpg', | |
'#attributes' => [ | |
'alt' => $this->t('Un texte alternatif'), | |
'title' => $this->t('Un titre'), | |
], | |
], | |
'#link' => [ | |
'#type' => 'link', | |
'#title' => $this->t('Titre du lien'), | |
// Utiliser fromRoute() pour un lien interne. | |
// Si on ne peut pas partir d'une route, et qu'on tient à utiliser le | |
// chemin (par exemple /test), utiliser internal: comme ceci : | |
// Url::fromUri('internal:/test'). | |
'#url' => Url::fromUri('https://fr.wikipedia.org/wiki/Marcel_Proust'), | |
], | |
'#image_with_link' => [ | |
'#type' => 'link', | |
'#title' => [ | |
'#theme' => 'image', | |
'#uri' => drupal_get_path('module', 'arthrolink_static_blocks') . '/images/example.jpg', | |
'#attributes' => [ | |
'alt' => $this->t('Un texte alternatif'), | |
'title' => $this->t('Un titre'), | |
], | |
], | |
'#url' => Url::fromUri('https://fr.wikipedia.org/wiki/Marcel_Proust'), | |
], | |
'#attached' => [ | |
'library' => ['arthrolink_static_blocks/static_block'], | |
], | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment