#StackBounty: #8 #toolbar Admin toolbar default left / vertical

Bounty: 50

On page load I need to

  • show the toolbar on the left / in vertical mode when in admin theme
  • hide the toolbar when in frontend theme

I’m looking for the event and the function to trigger those actions programmatically, e.g. something like

$(document).on('toolbar.loaded', Drupal.toolbar.setOrientationLeft);

and

$(document).on('toolbar.loaded', Drupal.toolbar.closeToolbar);

(I’m using the Admin Toolbar plugin)


Get this bounty!!!

#StackBounty: #8 #batch-api How do I structure the batch operations array?

Bounty: 50

I’m working on a Drupal 8 custom module to scrape pages from a site for migration. Since we’re dealing with a large number of pages, I wanted to set up batch processing, to deal with timeouts.

I looked at two tutorials, this one, and one here. However, when I ran my batch, it didn’t work as expected. The progress bar immediately filled up to all 71 items, and there were no imported pages, but a number of errors in the error log.

To rule out confounding factors, I created a simple module for testing the batch api (I didn’t find the batch represented in the D8 examples module). It exhibits the same behavior: it immediately processes all items, and there are no successes, just errors. This an the example error:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘Drupalbatch_testBatchTestForm’ not found in _batch_process() (line 252 of C:wamp64wwwD8coreincludesbatch.inc)
#0 C:wamp64wwwD8coreincludesbootstrap.inc(566): _drupal_error_handler_real(2, ‘call_user_func_…’, ‘C:wamp64wwwp…’, 252, Array)
#1 [internal function]: _drupal_error_handler(2, ‘call_user_func_…’, ‘C:wamp64wwwp…’, 252, Array)
#2 C:wamp64wwwD8coreincludesbatch.inc(252): call_user_func_array(‘Drupalbatch_t…’, NULL)
#3 C:wamp64wwwD8coreincludesbatch.inc(95): _batch_process()
#4 C:wamp64wwwD8coreincludesbatch.inc(77): _batch_do()
#5 C:wamp64wwwD8coremodulessystemsrcControllerBatchController.php(55): _batch_page(Object(SymfonyComponentHttpFoundationRequest))
#6 [internal function]: DrupalsystemControllerBatchController->batchPage(Object(SymfonyComponentHttpFoundationRequest))
#7 C:wamp64wwwD8corelibDrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#8 C:wamp64wwwD8corelibDrupalCoreRenderRenderer.php(574): DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}()

The following is the form that I’m using. Both of the tutorials indicate that calling _batch_process() is not necessary when calling batch_set() in a form submit.

namespace Drupalbatch_testForm;
use DrupalCoreFormFormStateInterface;
use DrupalCoreFormFormBase;

class BatchTestForm extends FormBase {

  public function getFormId() {
    return 'batch_test_admin_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Test Batch'),
      '#button_type' => 'primary',
    ];
    return $form;
  }

  public function submitForm(array &$form, FormStateInterface $form_state) {
    $batch = array(
      'title' => t('Test Batch'),
      'operations' => [],
      'finished' => 'DrupalBatchTestFormbatchCallback',
      'progress_message' => t('Processed @current out of @total.'),
    );

    for ( $i = 0; $i <= mt_rand(10,100); $i++ ) {
      $batch['operations'][] = ['Drupalbatch_testBatchTestForm::process',$i];
    }

    batch_set($batch);
  }

  public function process($input, &$context) {
    // log a random string
    Drupal::logger('batch_test')->notice(base64_encode(random_bytes(10)));
    sleep(mt_rand(1,100));
  }

  public function batchCallback($success, $results, $operations) {
    if ($success) {
      $message = Drupal::translation()->formatPlural(
        count($results),
        'One page scraped.', '@count pages scraped.'
      );
    }
    else {
      $message = t('Finished with an error.');
    }
    drupal_set_message($message);
  }
}

I suspect that something is wrong in the specification of the $batch variable, but I’ve cross-checked it, and it seems to conform to what the tutorials indicate.

The example in the documentation does not clearly indicate how to pass multiple data points to be called on with the same function.

  'operations' => array(
    array('my_function_1', array($account->id(), 'story')),
    array('my_function_2', array()),
  ),

Interestingly, one tutorial says to pass the data as a single array.

$batch = array(
  'title' => t('Deleting Node...'),
  'operations' => array(
    array(
      'Drupalbatch_exampleDeleteNode::deleteNodeExample',
      array($nids)
    ),
  ),
  'finished' => 'Drupalbatch_exampleDeleteNode::deleteNodeExampleFinishedCallback',
);

Another tutorial indicates to pass each data point as a separate element in the operations array.

$operations = [];
foreach ($letters as $letter) {
  $operations[] = ['smackmybatch_process_letter', [$letter]];
}

I’m not entirely sure what this one is specifying.

  'operations' => array(
    array('disc_migrate', array('courses', array('foo' => 'bar'))),
  ),

So, what is the correct way to pass the data that I want to have processed in the batch API?


Get this bounty!!!

#StackBounty: #8 #i18n-l10n Multilingual content and single language admin interface

Bounty: 100

I want my site’s content to be multi-lingual. I have a language switcher that can toggle between both the English and Spanish translations of a page. I want the administrative interface to always be in English, no matter whether you navigate to it from a Spanish or English translation of the page.

Here is my configuration at /admin/config/regional/language/detection:

enter image description here

Here is my configuration at user/1/edit:

enter image description here

My admin interface is always in English, but now my content is also always in English, no matter if I toggle the page to Spanish.

I have tried many settings, including the settings in Content language detection.

What is the correct configuration to achieve this?


/es/node/1

enter image description here

/admin/config/regional/language/detection/url

enter image description here

/admin/config/regional/language

enter image description here


Get this bounty!!!

#StackBounty: #8 #ckeditor Can't get Emoijone ckeditor plugin to appear on WSYISYG editor

Bounty: 50

I am trying to add the Emojione CKEditor plugin on a Drupal 8.3.7 site. I’ve created a module using the CKEditor API. I modeled it after both the youtube and smiley CKEditor plugin modules.

In my custom module, I’ve added the file src/Plugin/CKEditorPlugin/EmojioneCKEditorPlugin.php:

<?php

namespace DrupalemojionePluginCKEditorPlugin;

use DrupalckeditorCKEditorPluginBase;
use DrupaleditorEntityEditor;

/**
 * Defines the "emojione" plugin.
 *
 */
class EmojionePlugin extends CKEditorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return array(
      'Emojione' => array(
        'label' => t('emojione'),
        'image' => 'libraries/emojione/icons/emojione.png',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return 'libraries/emojione/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getDependencies(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return array();
  }

}

The above is basically what both the ckeditor_youtube and ckeditor_smiley have. The relevant methods seem to be getFile() and getButtons().

I have the relevant ckeditor plugin sources under libraries/.

When I enable my module and clear the cache and go to configure text formats and editors at /admin/config/content/formats, I don’t see the emojione button, but I do have buttons for smiley and youtube.

I’ve found this question and this answer, but in the answer, it isn’t clear in what file the Template class goes. Also, the answerer mentions some custom js, but doesn’t indicate where that goes either.

What am I missing?


Get this bounty!!!

#StackBounty: #8 #ckeditor Can't get Emoijone ckeditor plugin to appear on WSYISYG editor

Bounty: 50

I am trying to add the Emojione CKEditor plugin on a Drupal 8.3.7 site. I’ve created a module using the CKEditor API. I modeled it after both the youtube and smiley CKEditor plugin modules.

In my custom module, I’ve added the file src/Plugin/CKEditorPlugin/EmojioneCKEditorPlugin.php:

<?php

namespace DrupalemojionePluginCKEditorPlugin;

use DrupalckeditorCKEditorPluginBase;
use DrupaleditorEntityEditor;

/**
 * Defines the "emojione" plugin.
 *
 */
class EmojionePlugin extends CKEditorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return array(
      'Emojione' => array(
        'label' => t('emojione'),
        'image' => 'libraries/emojione/icons/emojione.png',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return 'libraries/emojione/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getDependencies(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return array();
  }

}

The above is basically what both the ckeditor_youtube and ckeditor_smiley have. The relevant methods seem to be getFile() and getButtons().

I have the relevant ckeditor plugin sources under libraries/.

When I enable my module and clear the cache and go to configure text formats and editors at /admin/config/content/formats, I don’t see the emojione button, but I do have buttons for smiley and youtube.

I’ve found this question and this answer, but in the answer, it isn’t clear in what file the Template class goes. Also, the answerer mentions some custom js, but doesn’t indicate where that goes either.

What am I missing?


Get this bounty!!!

#StackBounty: #8 #ckeditor Can't get Emoijone ckeditor plugin to appear on WSYISYG editor

Bounty: 50

I am trying to add the Emojione CKEditor plugin on a Drupal 8.3.7 site. I’ve created a module using the CKEditor API. I modeled it after both the youtube and smiley CKEditor plugin modules.

In my custom module, I’ve added the file src/Plugin/CKEditorPlugin/EmojioneCKEditorPlugin.php:

<?php

namespace DrupalemojionePluginCKEditorPlugin;

use DrupalckeditorCKEditorPluginBase;
use DrupaleditorEntityEditor;

/**
 * Defines the "emojione" plugin.
 *
 */
class EmojionePlugin extends CKEditorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return array(
      'Emojione' => array(
        'label' => t('emojione'),
        'image' => 'libraries/emojione/icons/emojione.png',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return 'libraries/emojione/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getDependencies(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return array();
  }

}

The above is basically what both the ckeditor_youtube and ckeditor_smiley have. The relevant methods seem to be getFile() and getButtons().

I have the relevant ckeditor plugin sources under libraries/.

When I enable my module and clear the cache and go to configure text formats and editors at /admin/config/content/formats, I don’t see the emojione button, but I do have buttons for smiley and youtube.

I’ve found this question and this answer, but in the answer, it isn’t clear in what file the Template class goes. Also, the answerer mentions some custom js, but doesn’t indicate where that goes either.

What am I missing?


Get this bounty!!!

#StackBounty: #8 #ckeditor Can't get Emoijone ckeditor plugin to appear on WSYISYG editor

Bounty: 50

I am trying to add the Emojione CKEditor plugin on a Drupal 8.3.7 site. I’ve created a module using the CKEditor API. I modeled it after both the youtube and smiley CKEditor plugin modules.

In my custom module, I’ve added the file src/Plugin/CKEditorPlugin/EmojioneCKEditorPlugin.php:

<?php

namespace DrupalemojionePluginCKEditorPlugin;

use DrupalckeditorCKEditorPluginBase;
use DrupaleditorEntityEditor;

/**
 * Defines the "emojione" plugin.
 *
 */
class EmojionePlugin extends CKEditorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return array(
      'Emojione' => array(
        'label' => t('emojione'),
        'image' => 'libraries/emojione/icons/emojione.png',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return 'libraries/emojione/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getDependencies(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return array();
  }

}

The above is basically what both the ckeditor_youtube and ckeditor_smiley have. The relevant methods seem to be getFile() and getButtons().

I have the relevant ckeditor plugin sources under libraries/.

When I enable my module and clear the cache and go to configure text formats and editors at /admin/config/content/formats, I don’t see the emojione button, but I do have buttons for smiley and youtube.

I’ve found this question and this answer, but in the answer, it isn’t clear in what file the Template class goes. Also, the answerer mentions some custom js, but doesn’t indicate where that goes either.

What am I missing?


Get this bounty!!!

#StackBounty: #8 #ckeditor Can't get Emoijone ckeditor plugin to appear on WSYISYG editor

Bounty: 50

I am trying to add the Emojione CKEditor plugin on a Drupal 8.3.7 site. I’ve created a module using the CKEditor API. I modeled it after both the youtube and smiley CKEditor plugin modules.

In my custom module, I’ve added the file src/Plugin/CKEditorPlugin/EmojioneCKEditorPlugin.php:

<?php

namespace DrupalemojionePluginCKEditorPlugin;

use DrupalckeditorCKEditorPluginBase;
use DrupaleditorEntityEditor;

/**
 * Defines the "emojione" plugin.
 *
 */
class EmojionePlugin extends CKEditorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return array(
      'Emojione' => array(
        'label' => t('emojione'),
        'image' => 'libraries/emojione/icons/emojione.png',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return 'libraries/emojione/plugin.js';
  }

  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getDependencies(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getLibraries(Editor $editor) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function getConfig(Editor $editor) {
    return array();
  }

}

The above is basically what both the ckeditor_youtube and ckeditor_smiley have. The relevant methods seem to be getFile() and getButtons().

I have the relevant ckeditor plugin sources under libraries/.

When I enable my module and clear the cache and go to configure text formats and editors at /admin/config/content/formats, I don’t see the emojione button, but I do have buttons for smiley and youtube.

I’ve found this question and this answer, but in the answer, it isn’t clear in what file the Template class goes. Also, the answerer mentions some custom js, but doesn’t indicate where that goes either.

What am I missing?


Get this bounty!!!

#StackBounty: #8 #links How to prevent the conversion of text URL to link?

Bounty: 50

I am creating a basic page having some text links as follows:

http://localhost:8080/student
http://localhost:8080
http://localhost:8080/login

D8 automatically converts this text URL to links as follows

http://localhost:8080/sutdent

http://localhost:8080

http://localhost:8080/login

I don’t want to convert the text URLs to links. I also checked the text filters but did not work for me.
enter image description here
How to prevent this conversion?


Get this bounty!!!

#StackBounty: #8 #taxonomy-terms #blocks How to get count on how many times a term is usen on a node

Bounty: 50

I’m about to create a Tag cloud module that shall have a block showing a list of all terms. The most used terms shall be in big text; the terms that not used often shall be in small text, as in the following screenshot.

I want to have a $count variable that holds the count of how many times each term is used.

I think that I can do so:

$database = Drupal::database();
$terms_count = $database
->query('SELECT COUNT(tid) FROM {taxonomy_index}')
->execute();

foreach($terms_count as $term_count) {
  print $term_count;
}

But it doesn’t show anything.

Any who knows?


Get this bounty!!!