使用表单元素中的值作为条件的Drupal查询到数据库

时间:2019-05-29 10:33:38

标签: mysql drupal drupal-blocks

我的任务是根据给定条件基于单选按钮的值进行选择。这是表格的代码,包含在BillfoldBlock.php中的 BLOCK CONTENT 中:

public function blockForm($form, FormStateInterface $form_state)
    {
      $config = $this->getConfiguration();

      $options = array(
        'fondo1' => t('Fondo 1'),
        'fondo2' => t('Fondo2'),
        'fondo3' => t('Fondo3'),
      );

      $form['enabled'] = array(
        // [
        '#type' => 'radios',
        '#title' => t('Selezionare un fondo'),
        '#options' => $options,
        '#description' => t('È possibile scegleire sono un fondo.'),
        '#default_value' => $options['fondo1'],
        // ],
        // [
        // '#type' => 'radio',
        // '#title' => t('Fondo 2'),
        // '#description' => t('Spunta questo box se desideri scegliere il Fondo 2.'),
        // '#default_value' => $config['disabled'],
        // ],
        // [
        // '#type' => 'radio',
        // '#title' => t('Fondo 3'),
        // '#description' => t('Spunta questo box se desideri scegliere il Fondo 3.'),
        // '#default_value' => $config['disabled'],
        // ]
      );

      return $form;
    }

这是数据库连接的逻辑:

public function billfoldLoad(array $entry = []) {
    // Read all the fields from the billfold table.
    $select = $this->connection
      ->select('billfoldblocks')
      // Add all the fields into our select query.
      ->fields('billfoldblocks')
      ->condition('valore', 1000, '>'); // HERE I WOULD LIKE TO PUT MY CONDITION ACCORDING TO THE VALUE OF THE CHOSEN RADIO BUTTON

    // Add each field and value as a condition to this query.
    foreach ($entry as $field => $value) {
      $select->condition($field, $value);
    }
    // Return the result in object format.
    return $select->execute()->fetchAll();
  }

0 个答案:

没有答案