Browse Source

Move ldp_contains to rdf_source bundle (#26)

* Move ldp_contains to rdf_source bundle

* Use a view to target the ldp_contains field

* Coding style
pull/756/head
Jared Whiklo 8 years ago committed by dannylamb
parent
commit
930c8c8924
  1. 60
      islandora/config/install/core.entity_form_display.fedora_resource.rdf_source.default.yml
  2. 25
      islandora/config/install/field.field.fedora_resource.rdf_source.field_ldp_contains.yml
  3. 18
      islandora/config/install/field.storage.fedora_resource.rdf_source.field_ldp_contains.yml
  4. 163
      islandora/config/install/views.view.fedora_entities_reference.yml
  5. 25
      islandora/src/Entity/FedoraResource.php
  6. 130
      islandora/src/Plugin/views/wizard/FedoraResource.php

60
islandora/config/install/core.entity_form_display.fedora_resource.rdf_source.default.yml

@ -0,0 +1,60 @@
langcode: en
status: true
dependencies:
config:
- field.field.fedora_resource.rdf_source.field_ldp_contains
- islandora.fedora_resource_type.rdf_source
id: fedora_resource.rdf_source.default
targetEntityType: fedora_resource
bundle: rdf_source
mode: default
content:
fedora_has_parent:
type: entity_reference_autocomplete
weight: 2
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
field_ldp_contains:
type: entity_reference_autocomplete
weight: 3
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
langcode:
type: language_select
weight: 4
settings: { }
third_party_settings: { }
name:
type: string_textfield
weight: 0
settings:
size: 60
placeholder: ''
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 5
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 6
third_party_settings: { }
user_id:
type: entity_reference_autocomplete
weight: 1
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }

25
islandora/config/install/field.field.fedora_resource.rdf_source.field_ldp_contains.yml

@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
config:
- field.storage.fedora_resource.rdf_source.field_ldp_contains
- islandora.fedora_resource_type.non_rdf_source
- islandora.fedora_resource_type.rdf_source
id: fedora_resource.rdf_source.field_ldp_contains
field_name: field_ldp_contains
entity_type: fedora_resource
bundle: rdf_source
label: ldp:contains
description: 'Contains Fedora Resource.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:fedora_resource'
handler_settings:
view:
view_name: bundles_of_fedora
display_name: entity_reference_1
arguments: { }
field_type: entity_reference

18
islandora/config/install/field.storage.fedora_resource.rdf_source.field_ldp_contains.yml

@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
module:
- islandora
id: fedora_resource.field_ldp_contains
field_name: field_ldp_contains
entity_type: fedora_resource
type: entity_reference
settings:
target_type: fedora_resource
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

163
islandora/config/install/views.view.fedora_entities_reference.yml

@ -0,0 +1,163 @@
langcode: en
status: true
dependencies:
module:
- islandora
- user
id: fedora_entities_reference
label: 'Fedora Entities Reference'
module: views
description: ''
tag: ''
base_table: fedora_resource_field_data
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: mini
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ‹‹
next: ››
style:
type: default
row:
type: fields
fields:
name:
id: name
table: fedora_resource_field_data
field: name
entity_type: fedora_resource
entity_field: name
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
filters:
status:
value: '1'
table: fedora_resource_field_data
field: status
plugin_id: boolean
entity_type: fedora_resource
entity_field: status
id: status
expose:
operator: ''
group: 1
sorts: { }
title: 'Bundles of Fedora'
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- user.permissions
tags: { }
entity_reference_1:
display_plugin: entity_reference
id: entity_reference_1
display_title: 'All Fedora Resource Entities'
position: 2
display_options:
display_extenders: { }
style:
type: entity_reference
options:
search_fields:
name: name
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- user.permissions
tags: { }

25
islandora/src/Entity/FedoraResource.php

@ -369,31 +369,6 @@ class FedoraResource extends ContentEntityBase implements FedoraResourceInterfac
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['ldp_contains'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('LDP Contains'))
->setDescription(t('Contains Fedora Resource.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'fedora_resource')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Fedora resource entity.'))

130
islandora/src/Plugin/views/wizard/FedoraResource.php

@ -0,0 +1,130 @@
<?php
namespace Drupal\islandora\Plugin\views\wizard;
use Drupal\views\Plugin\views\wizard\WizardPluginBase;
/**
* Tests creating node views with the wizard.
*
* Mostly copied from Nodes wizard, look there for more options.
*
* @ViewsWizard(
* id = "fedora_resource",
* base_table = "fedora_resource_field_data",
* title = @Translation("Fedora Resource")
* )
*/
class FedoraResource extends WizardPluginBase {
/**
* Set the created column.
*
* @var string
*/
protected $createdColumn = 'fedora_resource_field_data-created';
/**
* Override base method.
*
* Drupal\views\Plugin\views\wizard\WizardPluginBase::getAvailableSorts().
*
* @return array
* An array whose keys are the available sort options and whose
* corresponding values are human readable labels.
*/
public function getAvailableSorts() {
// You can't execute functions in properties, so override the method.
return array(
'fedora_resource_field_data-name:ASC' => $this->t('Name'),
);
}
/**
* {@inheritdoc}
*/
protected function defaultDisplayOptions() {
$display_options = parent::defaultDisplayOptions();
// Add permission-based access control.
$display_options['access']['type'] = 'perm';
$display_options['access']['options']['perm'] = 'access content';
// Remove the default fields, since we are customizing them here.
unset($display_options['fields']);
// Add the title field, so that the display has content if the user switches
// to a row style that uses fields.
/* Field: Content: Title */
$display_options['fields']['name']['id'] = 'name';
$display_options['fields']['name']['table'] = 'fedora_resource_field_data';
$display_options['fields']['name']['field'] = 'name';
$display_options['fields']['name']['entity_type'] = 'fedora_resource';
$display_options['fields']['name']['entity_field'] = 'name';
$display_options['fields']['name']['label'] = '';
$display_options['fields']['name']['alter']['alter_text'] = 0;
$display_options['fields']['name']['alter']['make_link'] = 0;
$display_options['fields']['name']['alter']['absolute'] = 0;
$display_options['fields']['name']['alter']['trim'] = 0;
$display_options['fields']['name']['alter']['word_boundary'] = 0;
$display_options['fields']['name']['alter']['ellipsis'] = 0;
$display_options['fields']['name']['alter']['strip_tags'] = 0;
$display_options['fields']['name']['alter']['html'] = 0;
$display_options['fields']['name']['hide_empty'] = 0;
$display_options['fields']['name']['empty_zero'] = 0;
$display_options['fields']['name']['settings']['link_to_entity'] = 1;
$display_options['fields']['name']['plugin_id'] = 'field';
return $display_options;
}
/**
* {@inheritdoc}
*/
protected function pageDisplayOptions(array $form, FormStateInterface $form_state) {
$display_options = parent::pageDisplayOptions($form, $form_state);
$row_plugin = $form_state->getValue(array('page', 'style', 'row_plugin'));
$row_options = $form_state->getValue(array('page', 'style', 'row_options'), array());
$this->display_options_row($display_options, $row_plugin, $row_options);
return $display_options;
}
/**
* {@inheritdoc}
*/
protected function blockDisplayOptions(array $form, FormStateInterface $form_state) {
$display_options = parent::blockDisplayOptions($form, $form_state);
$row_plugin = $form_state->getValue(array('block', 'style', 'row_plugin'));
$row_options = $form_state->getValue(array('block', 'style', 'row_options'), array());
$this->displayOptionsRow($display_options, $row_plugin, $row_options);
return $display_options;
}
/**
* Set the row style and row style plugins to the display_options.
*/
protected function displayOptionsRow(&$display_options, $row_plugin, $row_options) {
switch ($row_plugin) {
case 'full_posts':
$display_options['row']['type'] = 'entity:fedora_resource';
$display_options['row']['options']['view_mode'] = 'full';
break;
case 'teasers':
$display_options['row']['type'] = 'entity:fedora_resource';
$display_options['row']['options']['view_mode'] = 'teaser';
break;
case 'titles_linked':
case 'titles':
$display_options['row']['type'] = 'fields';
$display_options['fields']['title']['id'] = 'title';
$display_options['fields']['title']['table'] = 'fedora_resource_field_data';
$display_options['fields']['title']['field'] = 'title';
$display_options['fields']['title']['settings']['link_to_entity'] = $row_plugin === 'titles_linked';
$display_options['fields']['title']['plugin_id'] = 'field';
break;
}
}
}
Loading…
Cancel
Save