M
M
Matvey Kremnin2020-09-10 16:38:06
Drupal
Matvey Kremnin, 2020-09-10 16:38:06

How to display multiple fields in php in (field_view_field) or how to remake this function?

Tell me how to display several fields from the database on a page in Drupal 7, there is this Quotes module on the site that displays a random quote once a day.
In the types of material, I added the field of the author of the quote (before this field was not in the admin panel)
When publishing, I fill in the quote field and the author field accordingly, the quote is displayed, the author is not, since his field is not described in the module. I would be grateful for help.

I highlighted the part of the code where it displays the quote field on the page, I need to add the output of the author field of this quote (field_name_of_book)

I figured out how to display the author field in a handicraft way.

<?php

function quote_of_the_day_block_info() {
  $blocks['quote'] = array(
    'info' => t('Quote of the day'),
    'cache' => DRUPAL_NO_CACHE,
    'weight'=> -99,
    'status' => TRUE,
    'region' => 'content',
    'visibility' => BLOCK_VISIBILITY_LISTED,
    'pages' => '<front>',
  );
  return $blocks;
}

// Опредиление имяни блока, и его содержания
function quote_of_the_day_block_view($delta = '') {
  $block = array();
  if ($delta == 'quote') {
    $block = array(
      'subject' => '',
      'content' => quote_of_the_day_print_term(),
    );
  };
  return $block;
}

function quote_of_the_day_print_term() {
  $date = date("Y-m-d");
  $query = db_select('quote', 'q');
  $query->fields('q', array('node_id'));
  $query->condition('q.date', $date, '=');  // раз в день
  $result = $query->execute();

  $results_id = array();
  foreach($result as $row)
    array_push($results_id, $row->node_id);
    $result = $row->node_id;

  $one_res_id = [$results_id[$rand_results_id]];
  $two_res_id = 602;
  $res_id_arr = array_push($one_res_id, $two_res_id);
  $rand_res_id = array_rand($one_res_id, 1);*/

$node = node_load($result);
  $output = field_view_field('node', $node, 'field_quotation_text');
  $output = render($output);
  return $output;
}

/**
 * Implements hook_node_insert().
 */
function quote_of_the_day_node_insert($node) {
  if ($node->type == 'rundom_text') {
    db_merge('quote')
      ->key(array('node_id' => $node->nid))
      ->fields(array(
        'node_id' => $node->nid,
        'worked_quote' => NULL,
        'date' => NULL,
      ))
      ->execute();
  }
}

function quote_of_the_day_node_delete($node) {
  if ($node->type == 'rundom_text') {
    db_delete('quote')
      ->condition('node_id', $node->nid)
      ->execute();
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question