Skip to content

Instantly share code, notes, and snippets.

@datacodesolutions
Last active December 27, 2015 10:39
Show Gist options
  • Save datacodesolutions/7312650 to your computer and use it in GitHub Desktop.
Save datacodesolutions/7312650 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\blog\Controller;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller class for the blog module.
*/
class BlogController extends ControllerBase {
public function index()
{
$query = db_select('node_field_data', 'nfd');
$query->join('node__body', 'nb', 'nfd.nid = nb.entity_id');
$query->join('node__field_date', 'nfdate', 'nfd.nid = nfdate.entity_id');
$query->join('node__field_image', 'nfi', 'nfd.nid = nfi.entity_id');
$query->join('node__field_category', 'nfcat', 'nfd.nid = nfcat.entity_id');
$query->join('file_managed', 'fm', 'nfi.field_image_target_id = fm.fid');
$query->addField('fm', 'uri', 'image');
$query->addField('nfdate', 'field_date_value', 'date');
$query->addField('nfcat', 'field_category_value', 'category');
$query
->fields('nb', array('body_value', 'body_summary'))
->fields('nfd', array('nid', 'title', 'created'))
->condition('nb.bundle', 'blog_post', '=')
->range(0, 50);
$posts = $query->execute();
$result = \Drupal::service('twig')
->loadTemplate(drupal_get_path('module', 'blog') . '/templates/blog-index' . twig_extension())
->render(['posts' => $posts]);
return $result;
// return new Response($result);
// return array(
// array(
// '#theme' => 'blog_index',
// '#posts' => $posts,
// ),
// );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment