Create new module in Magento2 stable version? - magento2

As Stable version of Magento2 is released, how should we create a new module? What are the exact steps required to create a new module in Magento2 stable version ? Is there any way to convert Magento2 Beta module into stable version module ?
Looking forward to hear your thoughts.

I finally found a successful way to create a new module in stable Magento2 version:
Below are the list of files that you need to create in order to create a new module, my package name is Ktpl and module name is Brandmanager for this case.
1) Create module.xml at app/code/Ktpl/Brandmanager/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ktpl_Brandmanager" setup_version="2.0.0">
</module>
</config>
2) Create composer.json at app/code/Ktpl/Brandmanager/composer.json
{
"name": "ktpl/brandmanager",
"description": "Brand manager adds the facility to manage store brands in Magento2",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/module-store": "*",
"magento/module-backend": "*",
"magento/framework": "*"
},
"type": "magento2-module",
"license": "GPL-3.0",
"authors": [
{
"name": "KTPL",
"email": "chirag.bhavsar#krishtechnolabs.com"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Ktpl\\Brandmanager\\": ""
}
}
}
3) Create registration.php file at app/code/Ktpl/Brandmanager/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Ktpl_Brandmanager',
__DIR__
);
After placing these files run below command from Magento root.
sudo php -f bin/magento setup:upgrade
sudo rm -rf var/cache/*
sudo rm -rf var/page_cache/*
sudo rm -rf var/generation/*
This process will successfully register your module and you would be able to see you module at store -> Configuration -> Advanced -> Advanced section.

I am not going to give you a step by step guide, this isn't the place for such a answer.
Most notable change recently are requiring a registration.php and composer.json in the module route
Eg.
https://github.com/magento/magento2/blob/develop/app/code/Magento/AdminNotification/composer.json
https://github.com/magento/magento2/blob/develop/app/code/Magento/AdminNotification/registration.php
I would just base your new module of the core, it is the easiest way.

Related

How to use Magento 2 UI components in a custom module?

I'm trying to use Magento 2.4 UI components on a custom module. As per the documentation, I should add a dependency for the Magento_UI module:
To use UI components in your custom module, you need to add a dependency for the Magento_UI module in your component’s composer.json file.
https://devdocs.magento.com/guides/v2.4/ui_comp_guide/bk-ui_comps.html
How can I do that? I've tried to add the following line in my composer.json but this is obviously not the right syntax:
"require": {
"Magento_UI": "*"
},
To require a Magento module in your composer.json, you just need to add the required line in the "require" section of your composer.json:
{
...
"require": {
"magento/module-ui": "*"
},
...
}
You can find the list of Magento modules here: https://devdocs.magento.com/guides/v2.4/architecture/archi_perspectives/components/modules/mod_depend.html#hard-dependencies
...
"require": {
"magento/module-catalog": "103.0.*",
"magento/module-email": "101.0.*",
"magento/module-media-storage": "100.3.*",
"magento/module-store": "101.0.*",
"magento/module-theme": "101.0.*",
"magento/module-ui": "101.1.*",
"magento/module-variable": "100.3.*",
"magento/module-widget": "101.1.*",
"magento/module-authorization": "100.3.*"
}
...

Yii2 fork: dev-custom exists as yiisoft/yii2 but these are rejected by your constraint

I'm trying to use my forked version of yiisoft/yii2 in an installation of yii2-app-advanced.
I've followed this wiki.
I have created a branch named custom and pushed it to my yii2 fork.
In the composer.json of my fork I have the following (does it matter?):
...
"extra": {
"branch-alias": {
"dev-custom": "2.0.x-dev"
}
...
Then in my yii2-app-advanced installation I have the following composer.json:
{
"name": "yiisoft/yii2-app-advanced",
...
"minimum-stability": "stable",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/david-it/yii2"
}
],
"require": {
"php": ">=5.6.0",
"yiisoft/yii2": "dev-custom",
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
"yiisoft/yii2-bootstrap4": "~2.0.6"
},
...
}
When I run composer update I get the following error:
Problem 1
- The requested package yiisoft/yii2 dev-custom exists as yiisoft/yii2[2.0.0, 2.0.0-alpha, 2.0.0-beta, 2.0.0-rc, 2.0.1, 2.0.10, 2.0.11, 2.0.11.1, 2.0.11.2, 2.0.12, 2.0.12.1, 2.0.12.2, 2.0.13, 2.0.13.1, 2.0.13.2, 2.0.13.3, 2.0.14, 2.0.14.1, 2.0.14.2, 2.0.15, 2.0.15.1, 2.0.16, 2.0.16.1, 2.0.17, 2.0.18, 2.0.19, 2.0.2, 2.0.20, 2.0.21, 2.0.22, 2.0.23, 2.0.24, 2.0.25, 2.0.26, 2.0.27, 2.0.28, 2.0.29, 2.0.3, 2.0.30, 2.0.31, 2.0.32, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.1.x-dev, 3.0.x-dev, dev-master, 2.0.x-dev] but these are rejected by your constraint.
The command composer why-not yiisoft/yii2 dev-custom (if it is any useful here) shows this:
yiisoft/yii2-bootstrap4 2.0.8 requires yiisoft/yii2 (~2.0)
yiisoft/yii2-debug 2.1.13 requires yiisoft/yii2 (~2.0.13)
yiisoft/yii2-faker 2.0.4 requires yiisoft/yii2 (~2.0.0)
yiisoft/yii2-gii 2.1.4 requires yiisoft/yii2 (~2.0.14)
yiisoft/yii2-swiftmailer 2.1.2 requires yiisoft/yii2 (>=2.0.4)
I'm not sure what I am missing. I've looked around including this and this questions but with no luck.
EDIT 1
Composer 1.9.3 (2020-02-04 12:58:49) with PHP 7.2.24-0ubuntu0.18.04.3 on Linux / 4.15.0-91-generic
EDIT 2
Selecting dev-master as required works but the original files are downloaded (not the ones in the fork).
"require": {
...
"yiisoft/yii2": "dev-master",
...
}
I also tried all the tips from this answer with no luck.
At the moment, you have the custom branch. You need to create a branch named dev-custom in this situation, use the same branch name in require section of your composer.json file.
Your custom branch name must be prefixed with dev-.
After long hours of trial-and-error I've found two working solutions.
Solution 1 (With the help of Yii2 forum)
The branch apparently is considered "unstable", so you need to specify #dev to make composer work fine:
"require": {
...
"yiisoft/yii2": "dev-master#dev",
...
}
Solution 2
In the composer.json of my fork I've added an alias pointing to the branch:
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev",
"dev-custom": "2.0.n-dev"
}
}
Where n is just number (it should be unique among the versions available, I guess).
Then in the composer.json of my project I used "yiisoft/yii2": "2.0.n.x-dev".
I'm not quite sure why I have to use "2.0.n.x-dev" instead of "2.0.n-dev". A possible explanation is here.

dotnet new --install shows usage information

When I try to install a new template using the following:
dotnet new --install . --name MyTemplate
or
dotnet new --install "Path" --name MyTemplate
I get the usage information:
Usage: new [options]
Options:
-h, --help Displays help for this command.
-l, --list Lists templates containing the specified name. If no name is specified, lists all templates.
-n, --name The name for the output being created. If no name is specified, the name of the current directory is used.
-o, --output Location to place the generated output.
-i, --install Installs a source or a template pack.
-u, --uninstall Uninstalls a source or a template pack.
--nuget-source Specifies a NuGet source to use during install.
--type Filters templates based on available types. Predefined values are "project", "item" or "other".
--dry-run Displays a summary of what would happen if the given command line were run if it would result in a template creation.
--force Forces content to be generated even if it would change existing files.
-lang, --language Filters templates based on language and specifies the language of the template to create.
I have a .template.config directory with a template.json file within.
The contents of the template.json file are something like this:
{
"author": "My Department",
"classifications": [
"Solution Template"
],
"name": "My Template Name",
"identity": "My Template Identity",
"shortName": "mytemplate",
"tags": {
"language": "C#"
},
"sourceName": "Company.Product",
"preferNameDirectory": "true"
}
I certainly wish it would tell me what I'm doing wrong. This has worked for me in the past.
The way the dotnet new --install command works is a bit confusing unfortunately. The installation can be successful but the output does not make it obvious. You will get the usage information and a list of installed templates that should include your new one.
As mentioned in the comments, there is a bug filed that aims to tidy this up.
I was seeing similar results running dotnet new -i IdentityServer4.Templates, but the package wasn't being installed and no error or other info was being displayed.
Turns out nuget.org wasn't configured as a package source (new machine I guess? - thought that was configured by default when installing visual studio though).
Here's the nuget.org feed at the time of this writing:
https://api.nuget.org/v3/index.json
And here's info for configuring them in case it helps someone who hasn't done that:
https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio#package-sources

Wintersmith: error Error loading plugin './node_modules/wintersmith-coffee/': Cannot find module './plugin'

I built a site with wintersmith in November of 2013. It's live at http://powma.com
I'm coming back to it, but it's not building :-{
I don't mind getting my hands dirty, but I don't know where to start. I'm getting this error:
error Error loading plugin './node_modules/wintersmith-coffee/': Cannot find module './plugin'
Any suggestions?
Thanks!
Mike
UPDATE
Hey, this is because the coffeescript wasn't getting compiled.
I installed it globally, but that didn't help.
$ sudo npm install -g coffee-script
I manually compiled it and moved to other errors. Any suggestions for what's missing?
$ coffee -c plugin.coffee
Here's my config.json:
{
"locals":
{ "url": "http://localhost:8080"
, "title": "Powma"
, "subTitle": "Linking you to technology"
, "motto": "We build exceptions sites and applications to connect people to products, services, and each other."
, "owner": "Michael Cole"
, "profilePicture": "/static/img/profile-professional.jpg"
, "inlineSpriteMaxBytes" : 10000
},
"views": "./views",
"plugins":
[ "./node_modules/wintersmith-coffee/"
, "./node_modules/wintersmith-stylus/"
],
"require": {
"moment": "moment",
"_": "underscore",
"typogr": "typogr"
},
"jade": {
"pretty": true
},
"markdown": {
"smartLists": true,
"smartypants": true
},
"paginator": {
"perPage": 3
}
}
And package.json:
{
"name": "Powma-com",
"version": "0.1.1",
"private": true,
"engines": {
"node": "0.10.17"
},
"dependencies": {
"moment": "2.0.x",
"underscore": "1.5.x",
"typogr": "0.5.x",
"wintersmith": "2.0.x",
"wintersmith-stylus": "git://github.com/MichaelJCole/wintersmith-stylus.git#master",
"wintersmith-coffee": "0.2.x",
"express": "3.4.x",
"sendgrid": "~0.3.0-rc.1.7",
"express-validator": "~0.8.0",
"underscore-express": "0.0.4"
}
}
This is a new dev laptop I'm working with so that may be part of the problem.
I worked around the issue, but didn't fix it. Do I really need to manually compile the coffeescript?
Thanks!
I solved this issue by explicitly specifying plugin.coffee in the config.json file.
{
...other stuff...
"plugins":
[ "./node_modules/wintersmith-coffee/plugin.coffee"
, "./node_modules/wintersmith-stylus/plugin.coffee"
],
...more stuff...
}
It looks like you're missing wintersmith-coffee in node_modules; make sure you have it installed locally with npm install wintersmith-coffee. You can also try removing it from config.json if you're not using it anywhere.
It would also be helpful to see both your config.json and package.json. Also make sure you run an npm install and npm update to make sure you have everything referenced in package.json installed and updated.
Update
Not having CoffeeScript installed could have been the issue. After installing that globally, I'm not sure if all of your shell sessions will pick up the command and use it without being restarted. With a new shell session, see if you can build the site. You can also try testing Wintersmith in isolation of your site. Try generating a sample site with wintersmith new somepath and see if you can run wintersmith build there. That would be a good start for narrowing down your issues between your site and your workstation setup.

Include Zend In Symfony 2

I have a problem for including Zend Framework in Symfony 2 IN PRODUCTION, because when i use it on local there is no problem ...
I just commited my work on my production server and i have this error :
Fatal error: Class 'Zend_Gdata_AuthSub' not found
And there is this error for any classes of Zend Framework ...
This is my autoload which is good for localhost :
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
$loader->add('Zend_', __DIR__.'/../vendor/zf/library');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
set_include_path(__DIR__.'/../vendor/zf/library'.PATH_SEPARATOR.get_include_path());
return $loader;
?>
There is probably a problem with the include path but i don't know why ...
Thanks a lot !
If you want to use Composer to pull in the components you need from ZF2 then you could use the information at Zend Framework site Composer info page
As an example you can add code like this to your composer.json file to enable the repository:
"repositories": [
{
"type": "composer",
"url": "https://packages.zendframework.com/"
}
],
"require": {
"zendframework/zend-config": "2.0.*",
"zendframework/zend-http": "2.0.*"
},
You place the names of the packages you want to pull in under the "require" section and the list of available packages is at the link I supplied so you can check the names there.
When you go to install the dependencies you can use this command:
php composer.phar install
Does that help? :-)