8 – Multiple databases – Drupal Answers

I’m having trouble getting Drupal to switch between multiple databases. I have a system that involves connecting to an external database to retrieve data. I am using the following code inside of a form at build time to get some information for displaying in the form.

$connExternal = DrupalCoreDatabaseDatabase::getConnection('default', 'atavism');
$results = $connExternal->select('world');
$results->fields('world_name');
$data = $results->query();

$result = $data->fetchAll();

dpm(result);

However, when I visit the form, Drupal redirects me back to the install page, where it tells me that drupal is already installed. I have tried using setActiveConnection() as well, but the same thing keeps happening. I am not sure how to resolve it, and access the secondary database for retrieving the information I need.

Inside of my settings.php, I have this:

$databases('atavism')('default') = array (
  'database' => 'world',
  'username' => 'redacted',
  'password' => 'redacted',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\Core\Database\Driver\mysql',
  'driver' => 'mysql',
);

Am I missing something?

Is there any way to find and read answers again on Yahoo Answers?

Is there any way to find and read answers again on Yahoo Answers? – Web Applications Stack Exchange

tag removed – I need help understanding how to do these problems and how to find the answers using a calculator

tag removed – I need help understanding how to do these problems and how to find the answers using a calculator – MathOverflow

Dedicated user Permissions – Drupal Answers

I have the following Problem: I have two content types, Type A and Type B. Type B has a reference to Type B and I display the title of every referenced entity on the site of Type A and on the site of Type B I display the title of every sibling and the parent.

Now I want to integrate permissions. I figured out some ways to deal with this problem but that always sound complicated to the user and does not solve every problem. If you have some advice or a concrete solution that would be very appreciated. Basically I want to create a node of Type A, and then I want a role that allows the users with this role to edit the node. Furthermore, I want that users with this role to be able to create content of Type B and are only allowed to choose the reference for which they have the permission. Additionally, they should be able to edit all children of the page they have access to.

All pages should be readable to all users regardless of their permission.

Migration Plus entity_lookup fails – Drupal Answers

I’m trying to generate a taxonomy term if this does not already exist.
the migration file:

The taxonomy bundle name is function and the column in the spreadsheet
containing the values is ‘Functie’. However, I’m getting the following error:

(error) Error: Call to a member function getConfig() on null
in
Drupalmigrate_plusPluginmigrateprocessEntityLookup->determineLookupProperties() (line 217 of
/var/www/html/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php)

/var/www/html/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityLookup.php(182):
Drupalmigrate_plusPluginmigrateprocessEntityLookup->determineLookupProperties(‘field_function’)

/var/www/html/web/modules/contrib/migrate_plus/src/Plugin/migrate/process/EntityGenerate.php(116):
Drupalmigrate_plusPluginmigrateprocessEntityLookup->transform(‘Medewerker’,
Object(Drupalmigrate_toolsMigrateExecutable),
Object(DrupalmigrateRow), ‘field_function’)

/var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(394):
Drupalmigrate_plusPluginmigrateprocessEntityGenerate->transform(‘Medewerker’,
Object(Drupalmigrate_toolsMigrateExecutable),
Object(DrupalmigrateRow), ‘field_function’)

/var/www/html/web/core/modules/migrate/src/MigrateExecutable.php(203):
DrupalmigrateMigrateExecutable->processRow(Object(DrupalmigrateRow))

/var/www/html/vendor/drush/drush/includes/drush.inc(223): DrupalmigrateMigrateExecutable->import()

/var/www/html/vendor/drush/drush/includes/drush.inc(214): drush_call_user_func_array(Array, Array)

/var/www/html/web/modules/contrib/migrate_tools/src/Commands/MigrateToolsCommands.php(766):
drush_op(Array)

(internal function): Drupalmigrate_toolsCommandsMigrateToolsCommands->executeMigration(Object(DrupalmigratePluginMigration),
‘profiles’, Array)

/var/www/html/web/modules/contrib/migrate_tools/src/Commands/MigrateToolsCommands.php(321):
array_walk(Array, Array, Array)

(internal function): Drupalmigrate_toolsCommandsMigrateToolsCommands->import(‘profiles’,
Array)

/var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(257):
call_user_func_array(Array, Array)

/var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212):
ConsolidationAnnotatedCommandCommandProcessor->runCommandCallback(Array,
Object(ConsolidationAnnotatedCommandCommandData))

/var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(178):
ConsolidationAnnotatedCommandCommandProcessor->validateRunAndAlter(Array,
Array, Object(ConsolidationAnnotatedCommandCommandData))

/var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302):
ConsolidationAnnotatedCommandCommandProcessor->process(Object(SymfonyComponentConsoleOutputConsoleOutput),
Array, Array, Object(ConsolidationAnnotatedCommandCommandData))

/var/www/html/vendor/symfony/console/Command/Command.php(255):
ConsolidationAnnotatedCommandAnnotatedCommand->execute(Object(DrushSymfonyDrushArgvInput),
Object(SymfonyComponentConsoleOutputConsoleOutput))

/var/www/html/vendor/symfony/console/Application.php(978): SymfonyComponentConsoleCommandCommand->run(Object(DrushSymfonyDrushArgvInput),
Object(SymfonyComponentConsoleOutputConsoleOutput))

/var/www/html/vendor/symfony/console/Application.php(255): SymfonyComponentConsoleApplication->doRunCommand(Object(ConsolidationAnnotatedCommandAnnotatedCommand), Object(DrushSymfonyDrushArgvInput),
Object(SymfonyComponentConsoleOutputConsoleOutput))

/var/www/html/vendor/symfony/console/Application.php(148): SymfonyComponentConsoleApplication->doRun(Object(DrushSymfonyDrushArgvInput),
Object(SymfonyComponentConsoleOutputConsoleOutput))

/var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(118):
SymfonyComponentConsoleApplication->run(Object(DrushSymfonyDrushArgvInput),
Object(SymfonyComponentConsoleOutputConsoleOutput))

/var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(49): DrushRuntimeRuntime->doRun(Array,
Object(SymfonyComponentConsoleOutputConsoleOutput))

/var/www/html/vendor/drush/drush/drush.php(72): DrushRuntimeRuntime->run(Array)

/var/www/html/vendor/drush/drush/includes/preflight.inc(18): require(‘/var/www/html/v…’)

phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
/usr/local/bin/drush(10): require(‘phar:///usr/loc…’)

If anyone could point out what’s going wrong, by all means, enlighten me because I have no clue what’s going on, the configuration seems right to me.

Webform Wizard Confirmation Page – Drupal Answers

I have built a webform 4 page quiz and am using a Wizard pages. The last page of the quiz shows their computed results. I want to use that last page as the confirmation page. So when the user clicks next on the page before the last page, it submits their quiz and displays the results. How can I make the webform to submit using the last page of the quiz instead of sending the user to a confirmation page?

web applications – How to create a news feed (or news email) from a database with questions, answers and comments?

I have a web app where users can ask questions and get answers, ideas and comments from other users. Backend is Django Rest Framework with a Postgres Database, Frontend is React.

Now I want to add some ‘news-feed’ functionality, meaning e.g.:

  • users can ‘subscribe’ to questions
  • users get notifications/emails (daily or weekly) about updates in subscribed questions (E.g. “three new answers to your question xyz”!)
  • users see a ‘new’ badge attached to content that has been created since they last visited that question
    etc.

My naive approach would probably be something like:

  • add an ‘activity’ log to all ‘question’ objects in my database, with timestamps for each relevant action like: added answer with id, added comment with id, etc.
  • add a ‘subscriptions’ table linking users and questions, which also includes timestamps ‘lastViewed’ for each question
  • And create the news feed by comparing timestamps

But I’m sure there are lots of caveats here, regarding both logic and performance. But I’m sure this has been done before and there must be some ‘best practices’ to do it.

My best research result was this article: Designing a social media newsfeed on AWS which is focussing on a twitter/facebook style news-feed that needs to be delivered very quickly when users are visiting the site. And so it focusses on pre-generating and caching the news feed.

I’m looking for more insight in how to best approach the timestamp comparisons and database design, and on how to store/model the ‘news-feed’ itself. There’s probably articles out there about it, but I could not find them yet.

Thank you!!

Disclaimer: this is my second question on “Software Engineering”, please don’t be too harsh downvoting it.

worksheet function – Excel formula/solution for grading multiple choice questions with multiple answers

I have an Excel sheet where I input student test answers like so:

  1. A
  2. B
  3. A,B
  4. C,D

and compare these answers to the correct answers:

  1. A
  2. A
  3. B
  4. C,D,E

I know how to use an IF function to output ‘CORRECT’ in a cell if the student answer is correct (e.g. answer 1) and otherwise spit out ‘INCORRECT’.

What I can’t seem to do is find a formula which will spit out ‘CORRECT’ if correct (1); ‘INCORRECT’ if wrong (2); ‘MISTAKE’ if the student got one of the answers correct, but at the same time answered another choice incorrectly (3); and ‘MISSED’ if the student answered correctly but missed an answer (4).

Is there any way to do this? I’ve tried using wildcards and countifs but it’s beyond my Excel level.

Thanks in advance for any help!

hook_form_alter for a Webform – Drupal Answers

I have another post here:

Retrieve Webform submission data from database

I got some guidance but some of it wasn’t feasible for our application and the edited assistance was a bit general. Based on the person’s suggestions I am trying to use a hook_form_alter on a Webform module webform. Here’s the files and code I have.

cc_processing_getsubmissiondata.info.yml

name: 'CC Processing Get SubmissionData'
description: 'Provides a custom webform handler for retrieving the previous forms submission data'
core_version_requirement: ^8.8
Core: 8.x
package: Custom
type: module

CCProcessingGetSubmissionData.module

<?php

/**
 * Implementation of hook_form_alter
 */
 use DrupalCoreFormFormStateInterface;
 
 function CCProcessingGetSubmissionData_webform_submission_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
    echo "form alter hook triggered";
    
    if($form('#webform_id') == 'credit_card_billing_information') {
        echo "form alter form id found";
        $myValue = 'Jared';
        $form('elements')('credit_card_name')('#default_value') = $myValue;
    }
 }

I am not new to programming but am new to Drupal programming. I have some other code in the module that’s not in the answer suggestion on my previous post like the echos I found on other posts in an attempt to try to get something to happen that lets me know the the hook is being called. Both files are in modules/custom/cc_processing_getsubmissiondata. The folder structure I got off of a YouTube video on building hooks but it was just a short 8 minute basic hook video. From all the posts I’ve seen out there, everything I have looks correct but nothing happens. Any assistance in helping me getting this hook to work would be awesome. 🙂

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123