public static function FilterMailchimpCampaign::processCallback in Mailchimp 8
Same name and namespace in other branches
- 2.x modules/mailchimp_campaign/src/Plugin/Filter/FilterMailchimpCampaign.php \Drupal\mailchimp_campaign\Plugin\Filter\FilterMailchimpCampaign::processCallback()
Callback for preg_replace in process()
File
- modules/
mailchimp_campaign/ src/ Plugin/ Filter/ FilterMailchimpCampaign.php, line 41
Class
- FilterMailchimpCampaign
- Provides a filter to add content to and convert URLs for Mailchimp campaigns.
Namespace
Drupal\mailchimp_campaign\Plugin\FilterCode
public static function processCallback($matches = []) {
$content = '';
$entity_type = $entity_id = $view_mode = '';
foreach ($matches as $key => $match) {
switch ($key) {
case 1:
$entity_type = $match;
break;
case 2:
$entity_id = $match;
break;
case 3:
$view_mode = $match;
break;
}
}
$entity_type_manager = \Drupal::entityTypeManager();
$entity = $entity_type_manager
->getStorage($entity_type)
->load($entity_id);
if (!empty($entity)) {
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder($entity
->getEntityTypeId());
$build = $view_builder
->view($entity, $view_mode);
// Remove contextual links.
if (isset($build[$entity_type][$entity_id]['#contextual_links'])) {
unset($build[$entity_type][$entity_id]['#contextual_links']);
}
$content = render($build);
}
return $content;
}