-1

enter image description here

I 'm facing issue in custom module in Drupal 8.

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM first_view_table first_view_table LIMIT 11 OFFSET 0' at line 1: SELECT FROM {first_view_table} first_view_table LIMIT 11 OFFSET 0; Array ( )

Here is my view code fro my ex81 module:

function ex81_views_data() {
  $data = [];
  $data['mapping_data'] = []; 
  $data['mapping_data']['table'] = []; 
  $data['mapping_data']['table']['group'] = t('Ex81 View table');
  $data['mapping_data']['table']['provider'] = 'ex81_module';

  $data['first_view_table']['table']['base'] = [
    'field' => 'id',
    'title' => t('Ex811 View table'),
    'help' => t('Ex81 View table contains example content and can be related to nodes.'),
    'weight' => -10,
  ];


  $data['first_view']['table']['join'] = [
    'node_field_data' => [
      'left_field' => 'id',
      'field' => 'id',
      'extra' => [
        0 => [
          'field' => 'published',
          'value' => TRUE,
        ],
        1 => [
          'left_field' => 'age',
          'value' => 1,
          'numeric' => TRUE,
        ],
        2 => [
          'field' => 'published',
          'left_field' => 'is_active',
          'operator' => '!=',
        ],
      ],
    ],
  ];


  $data['mapping_data']['table']['join']['node_field_data'] = [
    'left_table' => 'foo',
    'left_field' => 'id',
    'field' => 'id',
    'extra' => [
      ['left_field' => 'project_code', 'field' => 'project_code'],
      ['field' => 'age', 'value' => 0, 'numeric' => TRUE, 'operator' => '>'],
    ],
  ];


  $data['mapping_data']['id'] = [
    'title' => t('Example content'),
    'help' => t('Relate example content to the node content'),
    'relationship' => [
      'base' => 'node_field_data',
      'base field' => 'id',
      'id' => 'standard',
      'label' => t('Example node'),
    ],
  ];

  $data['mapping_data']['tracking_no'] = [
    'title' => t('Tracking Number'),
    'help' => t('Just a Tracking Number field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

  $data['mapping_data']['ship_date'] = [
    'title' => t('Ship Date'),
    'help' => t('Just a Ship Date field.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

    $data['mapping_data']['order_no'] = [
    'title' => t('Order Number'),
    'help' => t('Just a Order Number field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
    'argument' => [
      'id' => 'string',
    ],
  ];

    $data['mapping_data']['recipient'] = [
    'title' => t('Receipient'),
    'help' => t('Just a Recipient field.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],
    'argument' => [
      'id' => 'string',
    ],
  ];

    $data['mapping_data']['item_description'] = [
    'title' => t('Item Description'),
    'help' => t('Just a Item Description field.'),
    'field' => [
      'id' => 'standard',
    ],
    'sort' => [
      'id' => 'standard',
    ],
    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

     $data['mapping_data']['no_of_units'] = [
    'title' => t('No Of Units'),
    'help' => t('Just a No Of Units field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

     $data['mapping_data']['total_invoice'] = [
    'title' => t('Total Invoice'),
    'help' => t('Just a Total Invoice field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];


     $data['mapping_data']['shipping_type'] = [
    'title' => t('Shiping Type'),
    'help' => t('Just a Shiping Type field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

   $data['mapping_data']['city'] = [
    'title' => t('City'),
    'help' => t('Just a City field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

     $data['mapping_data']['state'] = [
    'title' => t('State'),
    'help' => t('Just a state field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

    $data['mapping_data']['zip'] = [
    'title' => t('Zip'),
    'help' => t('Just a zip field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];

  $data['mapping_data']['age'] = [
    'title' => t('Age'),
    'help' => t('Just a numeric field.'),

    'field' => [
      'id' => 'numeric',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'numeric',
    ],

    'argument' => [
      'id' => 'numeric',
    ],
  ];


  $data['mapping_data']['is_active'] = [
    'title' => t('Is Active'),
    'help' => t('Just an on/off field.'),

    'field' => [
      'id' => 'boolean',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'boolean',
      'label' => t('Published'),
      'type' => 'yes-no',
      'use_equal' => TRUE,
    ],
  ];


  $data['mapping_data']['timestamp'] = [
    'title' => t('Timestamp'),
    'help' => t('Just a timestamp field.'),

    'field' => [
      'id' => 'date',
    ],

    'sort' => [
      'id' => 'date',
    ],

    'filter' => [
      'id' => 'date',
    ],
  ];


    $data['mapping_data']['username'] = [
    'title' => t('Winery Name'),
    'help' => t('Just a winery name field.'),
    'field' => [
      'id' => 'standard',
    ],

    'sort' => [
      'id' => 'standard',
    ],

    'filter' => [
      'id' => 'string',
    ],

    'argument' => [
      'id' => 'string',
    ],
  ];



  $data['views']['area'] = [
    'title' => t('Text area'),
    'help' => t('Provide markup text for the area.'),
    'area' => [
      'id' => 'text',
    ],
  ];

  return $data;
}

How to show this table in view?

  • I don't know what are you trying to do. I don't know why you are sharing that piece of code if you are working with views. In your view, in the field section, says: Broken/missing handler.... – user98716 May 21 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.