Created
January 2, 2015 03:05
-
-
Save star-szr/4374c2c8c9ee1bc14445 to your computer and use it in GitHub Desktop.
Example showing usage of the processed_text element in Drupal 8
This file contains 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\twitter_pull\Plugin\Block; | |
use Drupal\Core\Block\BlockBase; | |
/** | |
* Provides a block for executing PHP code. | |
* | |
* @Block( | |
* id = "twitter_pull_tweets_block", | |
* admin_label = @Translation("Twitter Tweets") | |
* ) | |
*/ | |
class TweetsBlock extends BlockBase { | |
/** | |
* Builds and returns the renderable array for this block plugin. | |
* | |
* @return array | |
* A renderable array representing the content of the block. | |
* | |
* @see \Drupal\block\BlockViewBuilder | |
*/ | |
public function build() { | |
$tweets = array( | |
(object) array('text' => 'Hey!'), | |
(object) array('text' => 'https://www.drupal.org'), | |
); | |
foreach ($tweets as $tweet) { | |
$cleanTweets[] = array( | |
'#type' => 'processed_text', | |
'#text' => $tweet->text, | |
'#format' => 'full_html', | |
// Potentially add keys for #filter_types_to_skip and #langcode. | |
); | |
} | |
$params = array('tweets' => $cleanTweets); | |
$tweet_template = array('#theme' => 'twitter_pull_tweet_listing', '#params' => $params); | |
return $tweet_template; | |
} | |
} |
This file contains 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
{% for tweet in params.tweets %} | |
<div class="tweet-wrapper"> | |
<div class="tweet-profile-image"> | |
{# Todo #} | |
</div> | |
<div class='tweet-text'> | |
{{ tweet }} | |
</div> | |
</div> | |
{% endfor %} |
This file contains 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
name: Twitter Pull | |
description: http://drupal.stackexchange.com/questions/139086/how-do-i-apply-check-markup-as-twig-filter/ | |
core: 8.x | |
type: module |
This file contains 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 | |
function twitter_pull_theme() { | |
return array( | |
'twitter_pull_tweet_listing' => array( | |
'variables' => array('params' => array()), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment