Drupal 8 hook_field_views_data错误未定义索引:表

时间:2018-05-02 10:09:21

标签: drupal drupal-modules drupal-views drupal-8

我编写了一个自定义模块,其中包含对自定义表的视图关系支持。

我已成功通过hook_field_views_data

中的moduleName.view.inc添加了该关系
function easyme_field_views_data(FieldStorageConfigInterface $field_storage) {
  $data = views_field_default_views_data($field_storage);
  foreach ($data as $table_name => $table_data) {
    $data[$table_name][$field_storage->getName() . '_value']['relationship'] = [
      'group'      => 'EasyMe',
      'id'         => 'standard',
      'base'       => 'easyme_event',
      'base field' => 'event_id',
      'label'      => t('EasyMe event from @field_name', ['@field_name' => $field_storage->getName()]),
    ];
  }
}

当我在视图中尝试并保存时,我收到此错误:

Notice: Undefined index: table in Drupal\views\Plugin\views\relationship\RelationshipPluginBase->calculateDependencies()

有人有解决方案吗?

在同一模块中,我还添加过滤器以在moduleName.module

中查看
function easyme_views_data_alter(&$data) {
  $data['views']['easysme_event_start_date'] = [
    'title'  => t('EasyMe event start date'),
    'help'   => t('Filter the view by EasyMe event start date.'),
    'filter' => [
      'group' => 'EasyMe',
      'id'    => 'easyme_start_date_filter',
    ],
  ];
  $data['views']['easysme_event_end_date']   = [
    'title'  => t('EasyMe event end date'),
    'help'   => t('Filter the view by EasyMe event end date.'),
    'filter' => [
      'group' => 'EasyMe',
      'id'    => 'easyme_end_date_filter',
    ],
  ];
}

如果添加了上述关系,我如何确保仅显示过滤器?

提前致谢。

0 个答案:

没有答案