-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DDST-455] BCELN24MIG-161: Feature/base fields #77
Changes from 5 commits
c4e0368
f016a20
a10d3f7
38f86bf
905f4b8
875a199
843ca51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
{ | ||
"name": "discoverygarden/islandora_citations", | ||
"type": "drupal-module", | ||
"require": { | ||
"require": { | ||
"islandora/controlled_access_terms": "^2", | ||
"seboettg/citeproc-php": "^2.6.0", | ||
"webflo/drupal-finder": "^1.2.2", | ||
"islandora/controlled_access_terms": "^2" | ||
"webflo/drupal-finder": "^1.2.2" | ||
}, | ||
"suggest": { | ||
"drupal/base_field_override_ui": "To allow the use of 'base' entity fields in mappings." | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,17 @@ | |
|
||
namespace Drupal\islandora_citations\Controller; | ||
|
||
use Drupal\Component\Render\FormattableMarkup; | ||
use Drupal\base_field_override_ui\BaseFieldOverrideUI; | ||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase; | ||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\Core\Entity\EntityFieldManager; | ||
use Drupal\Core\Entity\EntityFieldManagerInterface; | ||
use Drupal\Core\Field\Entity\BaseFieldOverride; | ||
use Drupal\Core\Field\FieldDefinitionInterface; | ||
use Drupal\Core\Link; | ||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\Core\Url; | ||
use Drupal\node\Entity\NodeType; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Returns responses for islandora_citations module routes. | ||
|
@@ -15,56 +22,63 @@ class IslandoraCitationsController extends ControllerBase { | |
use StringTranslationTrait; | ||
|
||
/** | ||
* The entity field manager. | ||
* Drupal's entity field manager service. | ||
* | ||
* @var \Drupal\Core\Entity\EntityFieldManager | ||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface | ||
*/ | ||
protected EntityFieldManagerInterface $entityFieldManager; | ||
|
||
protected $entityFieldManager; | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return parent::create($container) | ||
->setEntityFieldManager($container->get('entity_field.manager')); | ||
} | ||
|
||
/** | ||
* Construct. | ||
* Setter for the entity field manager service. | ||
* | ||
* @param \Drupal\Core\Entity\EntityFieldManager $entityFieldManager | ||
* The entity type manager service. | ||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager | ||
* The entity field manager service to set. | ||
* | ||
* @return $this | ||
*/ | ||
public function __construct(EntityFieldManager $entityFieldManager) { | ||
public function setEntityFieldManager(EntityFieldManagerInterface $entityFieldManager) : static { | ||
$this->entityFieldManager = $entityFieldManager; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Provide arguments for FieldConfigUpdate. | ||
* | ||
* @param string $node_type | ||
* @param \Drupal\node\Entity\NodeType $node_type | ||
* Node type. | ||
* | ||
* @return array | ||
* Form array. | ||
*/ | ||
public function provideArguments($node_type) { | ||
public function provideArguments(NodeType $node_type) { | ||
|
||
$header = [ | ||
'col1' => $this->t('Field'), | ||
'col2' => $this->t('CSL Field'), | ||
'col3' => $this->t('Operation'), | ||
]; | ||
$fields = $this->entityFieldManager->getFieldDefinitions('node', $node_type); | ||
$fields = $this->entityFieldManager->getFieldDefinitions('node', $node_type->id()); | ||
|
||
$rows = []; | ||
foreach ($fields as $field_definition) { | ||
|
||
if (!empty($field_definition->getTargetBundle())) { | ||
$data = $field_definition->getThirdPartySetting('islandora_citations', 'csl_field'); | ||
$dataForMappedEntities = $field_definition->getThirdPartySetting('islandora_citations', 'use_entity_checkbox'); | ||
$rows[] = [$field_definition->getName(), | ||
$rows[] = [ | ||
$field_definition->getName(), | ||
$data ? implode(',', $data) : ($dataForMappedEntities ? 'Mapped from entity' : '-'), | ||
[ | ||
'data' => new FormattableMarkup('<a href=":link">@name</a>', | ||
[ | ||
':link' => 'fields/node.' . $node_type . '.' . $field_definition->getName(), | ||
'@name' => $this->t('Edit'), | ||
]), | ||
], | ||
[ | ||
'data' => $this->getLinkToField('node', $node_type, $field_definition), | ||
], | ||
]; | ||
} | ||
} | ||
|
@@ -76,11 +90,59 @@ public function provideArguments($node_type) { | |
]; | ||
} | ||
|
||
/** | ||
* Helper; generate link to the field configuration page. | ||
* | ||
* @param string $type | ||
* The type of entity to which the field is associated. | ||
* @param \Drupal\Core\Config\Entity\ConfigEntityBundleBase $bundle | ||
* The bundle with which the field is associated. | ||
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition | ||
* The field definition of which to link to the configuration page. | ||
* | ||
* @return \Drupal\Core\Link|\Drupal\Core\StringTranslation\TranslatableMarkup | ||
* A link to a page to configure the given field, or a string. | ||
*/ | ||
protected function getLinkToField(string $type, ConfigEntityBundleBase $bundle, FieldDefinitionInterface $field_definition) { | ||
$add_destination = static function (Url $url) { | ||
$query = $url->getOption('query'); | ||
$query['destination'] = Url::fromRoute('<current>')->toString(); | ||
$url->setOption('query', $query); | ||
return $url; | ||
}; | ||
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride|\Drupal\field\Entity\FieldConfig $config */ | ||
$config = $field_definition->getConfig($bundle->id()); | ||
if ($config instanceof BaseFieldOverride) { | ||
if ($this->moduleHandler()->moduleExists('base_field_override_ui')) { | ||
return $config->isNew() ? | ||
new Link( | ||
$this->t('Add'), | ||
$add_destination(BaseFieldOverrideUI::getAddRouteInfo($config)), | ||
) : | ||
Comment on lines
+118
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An outdated comment is applicable to this section of code so linking for future reference #77 (comment) And yes I can confirm this is currently not applicable to the list of fields being iterated on, but I see no harm keeping it here in case things get extended/altered to iterate over all base fields rather than just the ones already included in a given content type. |
||
new Link( | ||
$this->t('Edit'), | ||
$add_destination(BaseFieldOverrideUI::getEditRouteInfo($config)), | ||
); | ||
} | ||
|
||
return $this->t('Not applicable'); | ||
} | ||
else { | ||
return new Link( | ||
$this->t('Edit'), | ||
$add_destination(Url::fromRoute("entity.field_config.{$type}_field_edit_form", [ | ||
$bundle->getEntityTypeId() => $bundle->id(), | ||
'field_config' => $config->id(), | ||
])), | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Provide arguments for FieldConfigUpdate. | ||
* | ||
* @param string $paragraphs_type | ||
* Node type. | ||
* @param \Drupal\paragraphs\Entity\ParagraphsType $paragraphs_type | ||
* Paragraph type. | ||
* | ||
* @return array | ||
* Form array. | ||
|
@@ -101,11 +163,7 @@ public function paragraphsArguments($paragraphs_type) { | |
$rows[] = [$field_definition->getName(), | ||
$data ? implode(',', $data) : '-', | ||
[ | ||
'data' => new FormattableMarkup('<a href=":link">@name</a>', | ||
[ | ||
':link' => 'fields/paragraph.' . $paragraphs_type->id() . '.' . $field_definition->getName(), | ||
'@name' => $this->t('Edit'), | ||
]), | ||
'data' => $this->getLinkToField('paragraph', $paragraphs_type, $field_definition), | ||
], | ||
]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much just:
$form['third_party_settings']
avoids have to separately handling things on submission.