Skip to content

Instantly share code, notes, and snippets.

@cyberlex404
Created October 10, 2017 21:15
Show Gist options
  • Select an option

  • Save cyberlex404/4cd1c55b62cf75d4f855cad9d6459ada to your computer and use it in GitHub Desktop.

Select an option

Save cyberlex404/4cd1c55b62cf75d4f855cad9d6459ada to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\housing\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Housing entities.
*/
class HousingViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
// subscription__housings
$data['housing']['subscription'] = [
'title' => $this->t('Subscription reverse'),
'help' => $this->t('Subscription to a Housing.'),
'field_name ' => 'name_subscription',
'relationship' => [
'field table' => 'subscription__housings',
'field field' => 'housings_target_id',
'field_name ' => 'name',
'id' => 'entity_reverse',
'base' => 'subscription',
'base field' => 'id',
'label' => $this->t('Subscription reverse'),
],
];
/*
$data['{MAIN ENTITY BASE TABLE}']['{useful non-conflicting name - I used the {RELATED ENTITY BASE TABLE}}'] = [
'title' => t('{some useful title that displays in Add Relationships popup}'),
'help' => t('{some useful description that displays in Add Relationships popup}'),
'relationship' => [
'field table' => '{name of intermediary table - it is probably {RELATED ENTITY}__{FIELD NAME}',
'field field' => '{name of intermediary field - it is probably {FIELD NAME}_target_id',
'base' => '{RELATED ENTITY BASE TABLE}',
'base field' => '{RELATED ENTITY ID FIELD}',
'id' => 'entity_reverse',
'label' => '{some useful label that displays in Relationship select in various views field settings popups}',
],
];
*/
return $data;
}
}
@cyberlex404
Copy link
Copy Markdown
Author

Notice: Undefined index: field_name in Drupal\views\Plugin\views\relationship\EntityReverse->query()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment