Created
January 7, 2019 19:19
-
-
Save ericjgruber/a0ada4bf2c98bcb39ab0e0a48866b7a9 to your computer and use it in GitHub Desktop.
Trim url from a Drupal preprocess field
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
/** | |
* Implements hook_preprocess_field(). | |
* @param $variables | |
*/ | |
function THEMENAME_preprocess_field(&$variables) { | |
$node = \Drupal::routeMatch()->getParameter('node'); | |
if ($node->hasField('field_links_social')) { | |
$twitter = $node->get('field_links_social')->getValue(); | |
$twitterURL = $twitter[0]["uri"]; | |
$regex = "@(https?://twitter.com/)@"; | |
$trimmedTwitter = preg_replace($regex, '', $twitterURL); | |
$variables['twitter'] = $trimmedTwitter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment