Skip to content

Commit

Permalink
fix js step copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
protitude committed Oct 16, 2023
1 parent 488f7d6 commit f11a9ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions js/tutorial-node-form.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(function ($) {
$(document).ready(function () {
function updateStepField() {
$( ".field--name-field-tut-body-image table tbody tr" ).each(function ( index, element ) {
var id = $(this).find(".image-widget input[type=hidden]").attr('value');
$( ".file-widget-multiple__table-wrapper table tbody tr" ).each(function ( index, element ) {
var id = $(this).find("span.file--image").attr('data-drupal-selector');
var hiddenInputId = $(this).find(".image-widget input[type=hidden]").attr('data-drupal-selector');
// Theme switched to using the wieght of the draggable item over the fid
// passing this along to correctly select the title input.
var stepWeight = thenum = hiddenInputId.match(/\d+/)[0];
id = id.match(/\d+/g).map(Number);
$(this).find('.tabledrag-hide').prev().prev().prev().prev().find('.form-item-field-tut-body-image-current-' + id + '-meta-title').find('label').text("Step Text");
$(this).find('.tabledrag-hide').prev().prev().prev().prev().find('.form-item-field-tut-body-image-current-' + id + '-meta-title').find('.description').text("This text will be added to your clipboard for the text in the step.");
$(this).find('.tabledrag-hide').prev().prev().prev().prev().find('.form-item-field-tut-body-image-current-' + id[1] + '-meta-title').find('label').text("Step Text");
$(this).find('.tabledrag-hide').prev().prev().prev().prev().find('.form-item-field-tut-body-image-current-' + id[1] + '-meta-title').find('.description').text("This text will be added to your clipboard for the text in the step.");
if ( !$(this).find('.tabledrag-hide').prev().find('button.copy-tutorial-fid').length ) {
$(this).find('.tabledrag-hide').prev().append('<button type="button" class="copy-tutorial-fid" onclick="copyFid(' + id + ", " + stepWeight + ')">Copy Step</button><br/><br/><strong>FID:</strong> ' + id);
$(this).find('.tabledrag-hide').prev().append('<button type="button" class="copy-tutorial-fid" onclick="copyFid(' + id[1] + ", " + stepWeight + ')">Copy Step</button><br/><br/><strong>FID:</strong> ' + id[1]);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions tutorial.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_field_widget_form_alter().
* Implements hook_field_widget_single_element_form_alter().
*/
function tutorial_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
function tutorial_field_widget_single_element_form_alter(&$element, FormStateInterface $form_state, $context) {
$field_defininition = $context['items']
->getFieldDefinition();

$field_name = method_exists($field_defininition, 'id') ? $field_defininition->id() : NULL;
if ($field_name == 'node.tutorial.field_tut_body_image') {
$element['#attached']['library'][] = 'tutorial/tutorial';
Expand Down

0 comments on commit f11a9ad

Please sign in to comment.