I display a block of type Assignment on the top of a page when I'm creating a node of type Submission. I need to access the fields of the Assignment block programmatically with my custom module.

Are there any built in Drupal functions that will allow me to do so?

I'm currently using hook_form_alter() but that does not give me access to the block elements.

  • What version of Drupal is it? How did you make your blocks fieldable? What module provides them? Views? Node Blocks? Sth else?
    – Mołot
    Commented Aug 24, 2015 at 20:57
  • I am using Drupal 7, the block is made from a view -> it displays another another node
    – Matt
    Commented Aug 24, 2015 at 20:59
  • This sounds pretty similar to this question asking about injecting content of a views block into a node.
    – Shawn Conn
    Commented Aug 24, 2015 at 21:06
  • I don't think it's similar. Poster wants to access a node field inside of a Views block, not insert a Views block inside of a node field. :) Commented Aug 25, 2015 at 3:09
  • Ah, I knew this sounded familiar: drupal.stackexchange.com/q/170528/28700. @Matt why open a new question when this has already been answered for you? If the answer is unsatisfactory, just reframe the question or ask for more clarification. Commented Aug 25, 2015 at 3:14

1 Answer 1


I found the value by first grabbing the assignment value from the URL, then looking up the path to find the node id, then loading that node and using a wrapper to find the value of that specific field.

        $url = $_SERVER['REQUEST_URI'];
        $pos = strpos($url, '?') + 1;
        $assignment = substr($url, $pos, strlen($url)); //get the assignment from the URL

        $nodeID = drupal_lookup_path('source', "student-assignments-new/" . $assignment);//get the path from the assignment - e.g. node/145
        $pos = strpos($nodeID, '/') + 1;
        $nid = substr($nodeID, $pos, strlen($nodeID));//get the node id

        $node = node_load($nid);

        $wrapper = entity_metadata_wrapper('node', $node); 
        $fieldValue = $wrapper->field_file_type_text->value();

        $output = $node->field_file_type_text[LANGUAGE_NONE][0]['value']; //field_file_type_text is my own field name
        return $output;
  • The striked lines initially worked for me, but whenever I uploaded a file - I would get an AJAX error and a 500 internal server error. The lines below it fixed the issue.
    – Matt
    Commented Aug 27, 2015 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.