How can i do the following query inside a block (i use php filter)

global $language;
$query = new EntityFieldQuery();
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', array('product'))
    ->propertyCondition('status', NODE_PUBLISHED)
    ->propertyCondition('language', $language->language, '=')
    ->fieldCondition('field_texture', 'fid', 'NULL', '!=')
    ->propertyOrderBy("type", "ASC")
    ->addMetaData('account', user_load(1));
$entities = $query->execute();

$items = '<option value="" selected="selected">Default</option>';
if (isset($entities['node'])) {
    foreach($entities['node'] as $obj) {
        $node = node_load($obj->nid);
        $uri = $node->field_texture['und'][0]['uri'];
        $url = file_create_url($uri);
        $title = $node->title;
        $items .= "<option value={$url}>{$title}</option>";

<form id="textures-form" accept-charset="UTF-8">
<div class="form-wrapper">
    <div class="form-item form-type-select" id="form-group-floors">
        <label for="floor-texture">Floors Texture:</label>
        <select id="floor-texture" name="floor_texture" class="form-select">
            <?php print $items; ?>
    <div class="form-item form-type-select" id="form-group-walls">
        <label for="wall-texture">Walls Textures:</label>
        <select id="wall-texture" name="wall_texture" class="form-select">
            <?php print $items; ?>
    <div class="form-item form-type-select" id="form-group-terrazo">
        <label for="terrazo-texture">Terrazo Textures:</label>
        <select id="terrazo-texture" name="terrazo_texture" class="form-select">
            <?php print $items; ?>
    <input type="button" value="Change" class="form-submit" onclick="return sendMessage()" />
    <input type="reset" value="Reset" class="form-submit" />

<div class="full">
<h3>How to use</h3>
Please wait until software loads the simulator, then choose wall and/or floor textures and click Change button to see the new materials applied.


Can you describe what is not working in the above? 

I see a few potential issues with the above. One of them is:


  $node = node_load($obj->nid);

EntityFieldQuery returns an array of objects. Each object (in Backdrop) contains the following properties:

  • entity_id
  • revision_id
  • bundle
  • entity_type

So, $obj->nid doesn't exist. You should do:

$node = node_load($obj->entity_id);

By the way, it's always a good idea to run any executable PHP code through Devel's Execute PHP Code window  to test it - that will make it easier to catch problems like the one I described above.  

Also best to load all nodes with node_load_multiple() then loop over them:

  $nodes = node_load_multiple(array_keys($entities['node']));
  foreach ($nodes as $node) {
    $uri = $node->field_texture['und'][0]['uri'];
    // etc.

And of course, probably best to create your block in code (in a module) than in a custom block (which I'm assuming is being done here).