Custom display suite field In a custom module I have defined a display suite field like so:

namespace Drupal\custom_dsfields\Plugin\DsField;
use Drupal\ds\Plugin\DsField\DsFieldBase;
//Views
/**
 * Plugin that renders the field.
 *
 * @DsField(
 *   id = "total_hours",
 *   title = @Translation("Total hours"),
 *   entity_type = "node",
 *   provider = "custom_dsfields",
 *   
 * )
 */
class MyField extends DsFieldBase
{
    /**
    * {@inheritdoc}
    */
    public function build(){

        $node = \Drupal::routeMatch()-&gt;getParameter('node');
        $entities = [];
        $hours = [];
        foreach ($node-&gt;field_hours as $key =&gt; $value) {
            array_push($entities, $value-&gt;target_id);
        }
        $entities = entity_load_multiple('user_entities', $entities, $reset = FALSE);
        foreach ($entities as $key =&gt; $value) {
            array_push($hours, $value-&gt;field_hours-&gt;value);
        }
        $hours_sum = array_sum($hours);

        return array(
            '#markup' =&gt; '&lt;strong&gt;Total hours for this day ' . $hours_sum . '&lt;/strong&gt;'
            // '#theme' =&gt; 'item_list',
            // '#items' =&gt; $hours_sum
            );
        }
    }


In the default display this works perfect. (open to improvements 
But when I use a view, and display the teaser display with this field in it then the field is not working. Why is this?

Some things I am questioning...


Am I loading the node in the correct way as I am not entirely sure what routeMatch() is doing.
Should I be doing this in a view template (hope not)


Thanks DSE!
I found a better way to access the node so this will work anywhere. 

$this-&gt;entity();


Inside the current class it will load the entity, in this case, the node.

Happy drupaling!