Can't get custom block module to appear in "Place blocks" screen in Drupal 8 - drupal-modules

I am trying to write a custom block module in drupal 8 that will allow me to place this block into my drupal pages using the block layout screen.
I'm very new to drupal - so this is very much a "hello world" project (initially) to figure out how this works. To this end, I have been following youtube video instructions as well as reading through whatever doco I can find on the net [and also a couple of books], but to no avail [yet].
What I have done, is created a directory "walker" in the modules folder in which I have created Walker.info.yml which looks like this:
name: Walker
description: A filewalker
core: 8.x
package: Custom
type: module
In the same directory I have created Walker.module which looks like this:
<?php
/**
* #file
* Code for the walker module.
*/
I have then created a directory:
module/walker/src/Plugin/Block/
and created a file called WalkerBlock.php with the following content:
<?php
/**
* #file
* Code for the walker block.
*/
namespace Drupal\walker\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a walker block
*
* #Block(
* id = "walker",
* admin_label = #Translation("The walker block"),
* category = #Translation("Blocks")
* )
*/
class WalkerBlock extends BlockBase
{
public function build()
{
return array('#markup' => 'Walker block');
}
}
If I run the command "find . -type f | grep Walker" from my root Drupal directory, I get the following output:
./modules/Walker/Walker.module
./modules/Walker/src/Plugin/Block/WalkerBlock.php
./modules/Walker/Walker.info.yml
Yet, though the documentation and videos I have read suggest that this should be all I require, the Walker block does not appear in the block layout screen as an option that I can place in one of the block regions.
Can anyone see what I'm doing wrong? I have been going around and around in circles for hours now.
Note also, that I have gone to the drupal8/admin/config/development/performance screen and clicked the "Clear all cache's" button
Thanks heaps for any assistance,
David Buddrige :-)

Check the module where you defined you block plugin is installed or not. If the module is not installed, go to the extend page of your site search for your module name and enable it. If you are using drush then you can simply enable it by
drush en moduleName
After that, I think you will get the block name in place block of your block layout section.

Related

How to get all URLs in a Symfony 4 project to contain the _locale

Am trying to create a language switcher for a Symfony 4 project (with Twig). Basically when clicking a link, the website's language will change.
Configuration I have is this:
config\packages\translation.yaml
framework:
default_locale: en
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- en
This is the important lines I got in
config\packages\services.yaml:
parameters:
locale: 'en'
# This parameter defines the codes of the locales (languages) enabled in the application
app_locales: en|fr
My Controller:
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\Json;
// Class name really should match Controller name
class ControllerBase extends AbstractController
{
/**
* #Route("/{_locale}", name="app_landing", defaults={"_locale" = "en"}, requirements={"_locale" = "en|fr"})
*/
public function index(Request $request)
{
$locale = $request->getLocale();
return $this->render('landing/index.html.twig');
}
}
The actual language switcher is just two list elements contained in the template file. They look like this:
<li>English</li>
<li>French</li>
This works fine.
Problem arises when clicking another link on the website. It doesn't contain the _locale and the site defaults back to en.
I really would like the _locale to be added to each link automatically (including the index path "/").
After a while of experimenting, I found the answer.
I tried to do the same thing in two different ways. In my case it was best to simply use the code in the template file and omit the {_locale} parameter in the controller.
Like that all works fine.

phppgadmin 5.1 Misc has a deprecated constructor

10 minute ago I tried to connect with phppgadmin 5.1 but i found this error message on web server error log :
" Misc has a deprecated constructor in /usr/share/phppgadmin/classes/Misc.php on line 8"
Phppgadmin is out of work.
I use php 7.0.
Someone knows how to fix it?
Thanks so much.
In my own research, in PHP 7, PHP 4 style constructors (methods that have the same name as the class they are defined in) are deprecated, and will be removed in the future. PHP 7 will emit E_DEPRECATED if a PHP 4 constructor is the only constructor defined within a class. Classes that implement a __construct() method are unaffected.
So my fix is open Misc.php, and locate the class Misc, in it there is a function called Misc, rename the function name with anything except for Misc because it will produce that error you've mentioned.
I found the same problem.Just browse and find Misc.php file it is located in classes folder inside your phpPgAdmin folder.Then,open it and search for Misc function and change it to anything except MIsc.In my case i changed it to Misc1.enter image description here
The easiest way to solve is to locate the Misc.php file in phppgadmin/classes/ and search for the the constructor function.You can see the class name is Misc and the constructor is also Misc.
This (notice) message is based on changes to PHP 7,So an old way of using a constructor is still in use, is what that message means.
What is expected is instead of having a class with a constructor like this:
<?php
class Misc{
function Misc() {
echo 'I am the constructor';
}
}
?>
would now be expected to look like this:
<?php
class Misc{
function __construct() {
echo 'I am the constructor';
}
}
?>
See the first section section of this PHP 7 deprecation info.
You can just comment out the old method and change it to the new method.It should work fine.
/* Constructor line : 15*/
Function __construct() {
}

Does anyone know where to find a SS2.0 JSDOC definition library?

Does anyone know or has a JSDOC definition library I can use for SS2.0??
The current one I have for SS1.0 looks like the one below, and I use it to plug into my IDE and get autocompletion.
/** * Loads an existing saved search. The saved search could have been created using the UI, or created using nlapiCreateSearch(type, filters, columns) in conjunction with nlobjSearch.saveSearch(title, scriptId).
*<br>API Governance: 5
* #param {String} recType [optional] - The record internal ID of the record type you are searching (for example, customer|lead|prospect|partner|vendor|contact). This parameter is case-insensitive.
* #param {String} searchId - The internal ID or script ID of the saved search. The script ID of the saved search is required, regardless of whether you specify the search type. If you do not specify the search type, you must set type to null and then set the script/search ID.
* #returns {nlobjSearch} nlobjSearch
* #since 2012.1 */
function nlapiLoadSearch(recType, searchId) { };
Not really a technical question but would come in handy for everyone.
You may consider what I did which there is no need to download other plugins. You will be able to enable the code assist if you have the copy of SS2.0 API and then use "#param" and "#type" JSDOC tag.
Then, there will be suggestion every time you type then 'CTRL' + 'SPACE".
Aside from that, your IDE will also provide description for each function.
So this is what will you do.
On your NetSuite accoun, download the SuiteScript 2.0 JavaScript files. You can do this by nagaviting at >Documents>Files>SuiteScripts>. Then at right portion of your screen, you should see links for "SuiteScript 2.0 API" and "SuiteSCript 1.0 API". Click for SS2.0 to download.
On Eclipse IDE, create a new JavaScript project for SS2.0 or include it on your existing project.
Next on the project you are working, right click then select “Properties”. Under >JavaScript>Include Path and then at “Projects” subtab, add the project where SS2.0 APIs are included.
You will now have code assist for object literal APIs of SS2.0. These are 'N/log' and 'N'util' modules.
Next to enable the code assist for object constructor APIs of SS2.0 like 'N/record' and 'N/search' modules, we should be adding "#param" JSDoc tag on each function declaration.
So if we are going to use the 'N/record', 'N/search' and 'N/error' modules in our script, we should have below sample comments before function declaration. But please take note that it should match the value inside the "{[VALUE HERE]}" tag and the module name. Also the variable name on the comment section and function declaration.
/**
* Do something.
*
* #param {record} objRec
* #param {search} objSearch
* #param {error} objError
*
*/
function doSomething(objRec, objSearch, objError)
{
//CODE HERE
}
You may also use '#type' for your variable declaration. Below is the sample code.
/**
* Do something.
*
*/
function doSomething()
{
/*** #type record**/
var recCustomerRefund = record.create(
{
type : 'customerrefund',
isDynamic : true
});
}
The way SS2 works you are essentially out of luck.
consider
define(['N/search'], function(bob){
var srch = bob.load({id:'customsearch_my_search'});
}
What is bob? Your IDE will have to be considerably smarter to know that bob is part of the search namespace. It's of course doable but less likely to work with a simple downloadable file that you can just plug into your IDE. If you just use 'search' that may make things more likely to work but now you've used up a very generic name that you cannot use elsewhere.
Also if an IDE can determine what 'bob' is now your arguments is an unordered hash so positional #params don't work anymore.
Typescript may help. I've been maintaining a Typescript definition file for SS1 at https://github.com/BKnights/KotN-Netsuite. As I start doing more with SS2.0 I may do the same for that. Then your IDE would have more of a chance:
define(['N/search'], function(bob:NSearch){...
So your Typescript aware IDE could use that for member completion and at least you'd have a compile time check on types

cakephp facebook component include paths on linux

I have a website on cakephp 1.3, with facebook integration. On my localhost(with windows os) it works fine, but on real hosting(with linux os) it gives this error Fatal error: Class 'Facebook' not found in /home/username/public_html/app/plugins/facebook/libs/f_b.php on line 22.
This is f_b.php
App::import('Vendor', 'Facebook.facebook/src/facebook');
App::import('Lib', 'Facebook.FacebookInfo');
class FB {
/**
* Facebook Api
*/
public static $Facebook = null;
public function __construct() {
if (empty(self::$Facebook)) {
self::$Facebook = new Facebook(FacebookInfo::getConfig()); } // 22 line
}
so, apparently it can not load Vender, I think there is a problem with paths, though this does not work either App::import('Vendor', 'Facebook.facebook'.DS.'src'.DS.'facebook');
f_b.php located in plugins/facebook/libs/ folder and this Facebook.php vendor is located in plugins/facebook/vendors/facebook/src folder
Thanks
Finally I found the solution of my problem, in order to work both on windows and linux it is necessary write like this
App::import('Vendor', 'Facebook.Facebook', array('file' => 'facebook/src/Facebook.php' ));
Here, are couple of example for that - Vendor examples
I’d say your paths don’t look right (why is there a dot?).
When I’ve used plugins with CakePHP, I’ve had to enable them by un-commenting the Plugins::loadAll() line in app/config/bootstrap.php. This will then make my library available in my CakePHP application.

Declaring function in Blocks in Drupal 6

I am facing an issue in declaring a fucation in block which I have added . I am calling a function by including an file which ia placed in the theme. I have also tried it by placing out of the theme folder. The function is alredy being user in front page. But when I am using the same function in that block. The screen gets blank and nothing displays. some part of my block coding is written below. Please help me.
<?php
global $base_url;
include($_SERVER['DOCUMENT_ROOT']."/travellar/geoiploc.php"); // indluded file
$ip = "203.189.25.0"; // Australia IP test
$country_code = getCountryFromIP($ip, "code");
I've had no problems loading functions from modules into custom blocks, but I've never tried loading one from a theme before. It's not clear to me whether or not theme functions are loaded before the page content is loaded.
You might have to create a custom module or include file to hold the function. Check out the module_load_include() function for how to load a specific include file.
A custom module would be a good approach as it is loaded before the theme layer and can be accessed from almost anywhere in Drupal except other modules with a lower weight than the custom module. It is also likely to come in handy for hooks and other overrides.
However, if you must have it in the theme layer, another option is adding it to template.php of your theme which should make it available within page.tpl.php and such, but not blocks I don't believe.
/sites/all/modules/mymodule/mymodule.info
name = My Module
package = !
description = It is MY module, not yours!
core = 6.x
The package "!" will make this module appear at the top of the modules page
/sites/all/modules/mymodule/mymodule.module
<?php
// Load mymodule.morePHP.inc
module_load_include('inc', 'mymodule', 'mymodule.morePHP');
// A custom function
function mymodule_my_custom_function($args) {
/* do custom stuff here */
return 'output';
}
/sites/all/modules/mymodule/mymodule.morePHP.inc
<?php
// An included custom function
function mymodule_other_custom_stuff() {
}

Resources