Question

Basically, I'm using the Aggregator module to import content from an RSS feed. The content is just a bunch of articles. I display this content in a view.

enter image description here

This is my current output, it shows the title and the date in a jcarousel. The thing I'm missing is the webpage source.

Currently, source url in views will have me a full link like:
https://whatiwant.com/the-article-name-i-dont-want
From the above, all I want to display is:
whatiwant.com

Here are my view settings:
enter image description here

I have tried adding different types of fields but none of them see to return the right value. Is there any way to perhaps strip the whole source url down to the base of it? I was thinking maybe it could be done programmatically however I need someone to point me in the right direction.

Was it helpful?

Solution

A way to do this would be to override the proprocess function get the domain like this:

function MY_MODULE_preprocess_views_view_field(&$variables) {
  $field = $variables['field'];

  if ($field->field == 'MY_LINK_FIELD_NAME') {
    $url = $variables['field']->getValue($variables['row'])[0];
    $parse = parse_url($url);
    $variables['output'] = $parse['host'];
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top