-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Prashant-bd/dgir-148
DGIR-148 : Add embargoed_file to embargo entity
- Loading branch information
Showing
6 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Install file. | ||
*/ | ||
|
||
use Drupal\Core\Field\BaseFieldDefinition; | ||
use Drupal\Core\Utility\UpdateException; | ||
|
||
/** | ||
* Add a new field to the existing Embargo entity type. | ||
*/ | ||
function embargo_update_8001() { | ||
$entity_type_id = 'embargo'; | ||
$bundle = 'embargo'; | ||
|
||
$definition_manager = \Drupal::entityDefinitionUpdateManager(); | ||
|
||
try { | ||
// Create a new field definition. | ||
$new_field = BaseFieldDefinition::create('entity_reference') | ||
->setLabel(t('Embargoed File')) | ||
->setDescription(t('New field for attaching media to the Embargo node.')) | ||
->setSetting('target_type', 'media') | ||
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED); | ||
|
||
// Install the new definition. | ||
$definition_manager->installFieldStorageDefinition('embargoed_file', $entity_type_id, $bundle, $new_field); | ||
} | ||
catch (UpdateException $e) { | ||
// Handle exception if needed. | ||
\Drupal::logger('embargo')->error('Error adding field: @error', ['@error' => $e->getMessage()]); | ||
return t('Update failed: @error', ['@error' => $e->getMessage()]); | ||
} | ||
|
||
// Provide a message indicating the update has been applied. | ||
return t('Added embargoed_file to the Embargo entity.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
custom_select_all_library: | ||
version: 1.x | ||
js: | ||
js/custom_select_all.js: {} | ||
dependencies: | ||
- core/jquery | ||
- core/once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(function ($, Drupal, once) { | ||
Drupal.behaviors.customSelectAll = { | ||
attach: function (context, settings) { | ||
// Create the link element | ||
var selectAllLink = $('<a href="#" id="edit-select-unselect-all">Select/Unselect All</a>'); | ||
|
||
// Use `once()` to ensure the link is prepended only once | ||
$(once('custom-select-all', '#edit-embargoed-file', context)).prepend(selectAllLink); | ||
|
||
// Attach the click handler directly to the link element | ||
selectAllLink.on('click', function (event) { | ||
event.preventDefault(); | ||
|
||
var checkboxes = $(':checkbox', context); // Target checkboxes within relevant context | ||
|
||
// Toggle checked state based on current state of the first checkbox | ||
checkboxes.prop('checked', !checkboxes.first().prop('checked')); | ||
}); | ||
} | ||
}; | ||
})(jQuery, Drupal, once); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters