How can I get the Register form on the front page in Drupal 8? - drupal-theming

I've been trying to get the create account form (register form) in a pop-up on the front page, without any success.
Can anybody here help me out with an example that works?
I've tried adapting examples from Drupal 7 but couldn't get them to work, I've tried to make a custom form but it didn't work, I've tried installing modules that could handle this but they also didn't work.
The last attempt I've made to resolve this problem was:
<?php
/**
* #file
* Functions to support theming in the themename theme.
*/
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*/
function themename_preprocess_html(&$variables) {
$form = \Drupal::formBuilder()->getForm('Drupal\user\register');
return $form;
}
Any help would be greatly appreciated.
Thank you!

you can use this module: https://www.drupal.org/project/formblock which exposes some additional forms as blocks (like the user registration, new password, contact, etc..). So after you install it you can just configure the block to appear only on the front page. The registration block will not be available for authenticated users or if the anonymous users are not allowed to create new accounts.
However, you will also have to apply this patch https://www.drupal.org/node/2570221 (if it will not be already committed by the time you check it) if you use the latest Drupal8 stable version, otherwise you will get a fatal error.

This link explains how it can be used to programmatically render the login and registration forms.
http://web-tricks.org/content/how-render-user-login-form-and-user-register-form-drupal-8
For the login form
$form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class) ;
$render = Drupal::service('renderer');
$variables['login_form'] = $render->renderPlain($form);
and for register form
$entity = \Drupal::entityTypeManager()->getStorage('user')->create(array());
$formObject = \Drupal::entityTypeManager()
->getFormObject('user', 'register')->setEntity($entity);
$form = \Drupal::formBuilder()->getForm($formObject);
$variables['register_form'] = \Drupal::service('renderer')->render($form);

Related

How to use WHMCS Local api (internal API)

How to use WHMCS LocalAPI (InternaAPI)
Hi
I have a problem to use WHMCS LocalAPI
WHMCS Documentation is very poor and unclear about this problem
when I run this code a blank page appear and any thing is happened
<?php
require('../init.php');
require('../includes/api.php');
$command = 'AddOrder';
$postData = array(
'clientid' => '1',
'domain' => array('domain1.com'),
'billingcycle' => array('annually'),
'domaintype' => array('register',),
'regperiod' => array(1),
'nameserver1' => 'ns1.demo.com',
'nameserver2' => 'ns2.demo.com',
'paymentmethod' => 'zarinpalgw',
);
$adminUsername = 'myadminname'; // Optional for WHMCS 7.2 and later
$results = localAPI($command, $postData, $adminUsername);
print_r($results);
?>
I expected to add order after run this code
External API is very slow and not suitable for me for some reason such as
I have a dynamic IP and External API work with static IP because IP must be recognize in WHMCS->General setting->Security
The Internal API code in your example looks like it should work. Temporarily enabling PHP errors can help narrow down the exact cause of this issue (Setup > General Settings > Other > Display Errors), although I believe it is due to the way you are initializing the WHMCS environment in your PHP file.
WHMCS provides specific guidelines on building custom pages, which appears to be what you were trying to do in the example provided. Custom PHP files must be located in the root WHMCS directory, however require('../init.php'); indicates that your script is currently inside a subdirectory. You also should not be requiring api.php, as that is already being handled by init.php. Moving your script to the WHMCS root directory and commenting out the require('../includes/api.php'); line should hopefully fix the blank page issue.
Please note: the example you provided does not display the normal WHMCS client interface and does not check to see if the user is logged in. If that is functionality you will be needing as well, you can create a page with the same interface and functionality as a native WHMCS client area page. The following is a slightly modified version of the example code WHMCS provides in their guide for creating client area pages:
<?php
// Define WHMCS namespaces
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
// Initialize WHMCS client area
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle('Your Page Title Goes Here');
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name');
$ca->initPage();
// Uncomment to require a login to access this page
//$ca->requireLogin();
// Uncomment to assign variables to the template system
//$ca->assign('variablename', $value);
// Code to run when the current user IS logged in
if ($ca->isLoggedIn()) {
$clientName = Capsule::table('tblclients')->where('id', '=', $ca->getUserID())->pluck('firstname');
$ca->assign('clientname', $clientName);
// Code to run when the current user is NOT logged in
} else {
$ca->assign('clientname', 'Random User');
}
// Setup the primary and secondary sidebars
Menu::addContext();
Menu::primarySidebar('announcementList');
Menu::secondarySidebar('announcementList');
// Define the template filename to be used (without the .tpl extension)
$ca->setTemplate('mypage');
// Display the contents of the page (generated by the Smarty template)
$ca->output();

Prestashop LOG: get DUMP of Object and Array

I am figuring out how Prestashop 1.7 works and I have some experience with Symfony.
In Symfony development mode [Symfony project url]/_profiler is useful, among other things, to check the dump($someVariable) of variables in a request.
With Prestashop 1.7 in the admin mode it is possible to do [Prestashop project url]/admin[some random chain of chars]/_profiler to display the Symfony _profiler and analyse what's going on in the requests concerning the admin mode.
But if outside the admin mode (in the virtual shop demo mode), [Prestashop project url]/_profiler or [Prestashop project url]/[language value]/_profiler does not display the Symfony _profiler.
I have tried Prestashop own profiler by activating define('_PS_DEBUG_PROFILING_', true); in [prestashop project]/config/defines.inc.php. It displays Prestashop profiler at the bottom of the "virtual shop demo mode" but this one does not include dump($someVariable) that could be used, for development and to understand Prestashop behaviour, in a hookAction[action name].
I've managed to get the Symfony dump($someVariable) with hookDisplay[display name] through the HTML generated but not in a hookAction[action name] which is what I am looking for.
UPDATE
Looking at Prestashop 1.7 code I almost have the feeling that Symfony is only used on the Admin side, because I can see:
$kernel = new AppKernel(_PS_MODE_DEV_?'dev':'prod', _PS_MODE_DEV_); in [Prestashop project url]/admin[some random chain of chars]/index.php but I don't see it in [Prestashop project url]/index.php.
Best solution I've found so far is to create a custom logger similar to the one explained here
I've created file: [Prestashop project]/modules/[my module]/classes/CustomLogger.php
<?php
class CustomLogger {
const DEFAULT_LOG_FILE ="prestashop_system.log";
public static function log($message, $level = 'debug', $fileName = null){
$fileDir = _PS_ROOT_DIR_ . '/log/';
$fileName=self::DEFAULT_LOG_FILE;
if(is_array($message) || is_object($message)){$message = print_r($message, true);}
$formatted_message=$level." -- ".date('Y/m/d - H:i:s').": ".$message."\r\n";
return file_put_contents($fileDir . $fileName, $formatted_message, FILE_APPEND);
}
}
?>
In '[Prestashop project]/modules/[my module]/[my module].php' it is declared at the top:
include_once dirname(__FILE__).'/classes/CustomLogger.php';
And use CustomLogger::log($[some variable]); in your code.

How to have global $user variable in Laravel 5.2?

Context
Laravel ships with two authentication controllers out of the box, which are located in the App\Http\Controllers\Auth namespace.
...
You may access the authenticated user via the Auth facade: $user = Auth::user();
Reference: Laravel 5.2 Documentation
I'm able to log in successfully and I'm redirected to the correct place as defined in the AuthController.php, but now I need access to the $user object in most of my views such as for checking the user's information, access priveleges, etc.
Problem
How do I properly provide access to the $user variable on all of my views?
How other people have been doing it
User imJohnBen of Laracast asked how a Laravel 5 service provider can be used to share view variables. He later shares how he was able to use the existing ComposerServiceProvider and added a GlobalComposer to be able to share variables on all the views.
I followed his answer but there was a missing step. I couldn't contribute to the Laracast forums, thus leading to the creation of this StackOverflow question.
The Laravel version I'm using here is Laravel 5.2.*.
Answer
Find the existing ComposerServiceProvider class. I found mine in vendor/laravel/framework/src/Illuminate/Foundation/Providers/ComposerServiceProvider.php.
Import/reference the ViewFactory dependency at the top of the file.
use Illuminate\Contracts\View\Factory as ViewFactory;
Add the boot method, or modify it if it exists already. Make sure the ViewFactory was injected (add it as a parameter in the boot function):
/**
* Register bindings in the container.
*
* #return void
*/
public function boot(ViewFactory $view)
{
$view->composer('*', 'App\Http\ViewComposers\GlobalComposer');
}
Make a ViewComposers folder in your app/Http folder.
Make a GlobalComposer.php file in the ViewComposers folder, containing the following:
<?php
namespace App\Http\ViewComposers;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
class GlobalComposer {
/**
* Bind data to the view.
*
* #param View $view
* #return void
*/
public function compose(View $view)
{
$view->with('user', Auth::user());
}
}
(The missing step) Finally, make sure everything is wired up by going to your config/app.php file and making sure that ComposerServiceProvider is in your providers list.
'providers' = [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
// etc...
Illuminate\Foundation\Providers\ComposerServiceProvider::class,
]
Afterwards, the $user variable and any other variables you define in the GlobalComposer will be accessible in any of the views you render.

Couldn't get the uid in Odoo JavaScript

I'm trying to learn JavaScript for Odoo. I've created a new class in my custom module's js file.
openerp.odoojs = function(instance){
console.log('instance: ',instance);
console.log('session: ',instance.session);
}
This is what I'm getting when I browse the session object in the console.
But when I try to access the uid or any other attribute or parameter like instance.session.uid, I'm getting it as undefined. Please help! I'm stuck with this. I'm unable proceed further.
Try to extend the 'Backbone.Model' like 'PosModel' in 'model.js' file. Try to define the 'initialize' function, where you will find two parameters in function arguments as 'session' and 'attributes'. Here you can find the uid using 'session.uid'.

Magento1.9.1 Please make sure your password match issue

I am encountering this issue in CE1.9.1.
When a User registers (doesn't matter if its during checkout or from the Create an Account link) the user keeps getting the password mismatch error even though the password is re-entered correctly.
The form validation does not indicate a miss-match, but once a user clicks on Register it returns the mismatch error.
There is no errors in the chrome console...
I found this: https://magento.stackexchange.com/questions/37381/please-make-sure-your-passwords-match-password-error-in-checkout-with-new-re
But I don't believe it is the same error.
I need to fix it soon, any help is greatly appreciated!
We also had this issue with 1 of our webshops. However we used a checkout extension. So im not sure if this applies for the regular standard checkout. Anyway.
The question should be, are u using a checkout extension?
If so, the value inside the model's file of that extension is set at:
$customer->setConfirmation($password);
but should be:
$customer->setPasswordConfirmation($password);
For me this worked, without changing anything in the core. It's just that the extensions should get a small update, or you can do it manually like i did. Just find that line in the files of the model map of your extension.
as workaround you can use folloing code:
$confirmation = $this->getConfirmation();
$passwordconfirmation = $this->getPasswordConfirmation();
//if ($password != $confirmation) {
if (!(($password == $confirmation) ||
($password == $passwordconfirmation))) {
$errors[] = Mage::helper('customer')->__('Please make sure your passwords match.');
}
Changing app/code/core/Mage/Customer/Model/Customer.php as proposed by #Pedro breaks the functionality of "forgot password" and "edit customer account" pages. Instead, make the following changes to
app/code/core/Mage/Checkout/Model/Type/Onepage.php
by editing lines starting from 369
if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
// set customer password
$customer->setPassword($customerRequest->getParam('customer_password'));
$customer->setConfirmation($customerRequest->getParam('confirm_password'));
} else {
// emulate customer password for quest
$password = $customer->generatePassword();
$customer->setPassword($password);
$customer->setConfirmation($password);
}
and set the PasswordConfirmation -Property and not the Confirmation-Property of the Customer-Object:
if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
// set customer password
$customer->setPassword($customerRequest->getParam('customer_password'));
$customer->setPasswordConfirmation($customerRequest->getParam('confirm_password'));
} else {
// emulate customer password for quest
$password = $customer->generatePassword();
$customer->setPassword($password);
$customer->setPasswordConfirmation($password);
}
Encountered the same problem and fixed it. Snel's answer is closer to right answer. The problem could lay in the external/local modules, so you should check not the
app/code/core/Mage/Checkout/Model/Type/Onepage.php
And of course do NOT modify it in any case!
But you should find _validateCustomerData() method which is used in your case. Use Mage::log() or debug_backtrace() for it. It may look something like (but not exactly, because this part could be modified for some reason):
if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
// set customer password
$customer->setPassword($customerRequest->getParam('customer_password'));
$customer->setConfirmation($customerRequest->getParam('confirm_password'));
} else {
// emulate customer password for quest
$password = $customer->generatePassword();
$customer->setPassword($password);
$customer->setConfirmation($password);
}
Those modules extend the old version of core file so if you module wasn't updated, you should change them yourself and change
setConfirmation()
to its current usable analog:
setPasswordConfirmation()
I also had this same problem. I'm not comfortable with code so I wanted to avoid all the above fiddling. To fix it all I did was update my extensions, and I also disable one page checkout, cleared cache, then re-enabled one-page checkout.
This has now fixed the problem without needing to modify code.
hope it helps for you.
If anybody still can't figure out, why this is happening:
The Conlabz Useroptin extension (http://www.magentocommerce.com/magento-connect/newsletter-double-opt-in-for-customers.html) can cause this behavior aswell.
Unless this truly is a core bug, I wouldn't recommend changing core files.But i sloved this way Open app\code\core\Mage\Customer\Model\Customer.php and edit your code like below
$confirmation = $this->getConfirmation();
$passwordconfirmation = $this->getPasswordConfirmation();
//if ($password != $confirmation) {
if (!(($password == $confirmation) ||
($password == $passwordconfirmation))) {
$errors[] = Mage::helper('customer')->__('Please make sure your passwords match.');
}
I had the same issue after updating to 1.9.2.1 and was unable to resolve using some of the suggested code changes here and elsewhere - also very reluctant to change core code for obvious reasons.
My solution - a configuration update. It was:
Enable OnePage Checkout = Yes
Allow Guest Checkout = Yes
Require Customer to be Logged in = No
I updated to Yes/No/Yes as per the above and cleared the cache. This resolved the issue by inserting the standard customer registration form (rather than appending the registration to end of the billing info) and passing that info to the billing form on successful registration.
It seems there is a code issue here along the lines of the other responses but this was an excellent workaround for me. Hope it helps.
Change this code
app\code\core\Mage\Customer\Model\Customer.php
$confirmation = $this->getPasswordConfirmation();
to this code
$confirmation = $this->getConfirmation();