Today we will discuss about, how to create new tab in custom module and set the linking. So before start, we will clear some points for custom module.
1. "module_name.links.task.yml" and "module_name.routing.yml" is important file, if we are going to create tabs.
2. Now Please follow the syntax, we will explain here for all parameters and syntax for tabs.
Example Syntax: Here 'account_login' is example of my module name..
account_login.tab_1: // This is the Tab Routers
route_name : account_login.content // This is route name and we will use this in routing.yml file when we create routers and path
title: account login // This is Title of Tabs.
base_route: account_login.content // This is for set default open Tab
weight: 10 // This is for tab weight or for order of Tab
account_login.tab_2: // This is for second Tab Router
route_name: account_login_otp.content // This is route name and we will use this in routing.yml file when we create routers and path
title: Work // This is Title of Tabs.
base_route: account_login.content // This is for set default open Tab
weight: 20 // This is for tab weight or for order of Tab
Now we will create "routing.yml" file.
Example Syntax: Here 'account_login' is example of my module name..
account_login.content: // so we will use same route name for first tab which we use in 'links.task.yml' file
path: '/account/login'
defaults:
# Calls the list controller, defined in the annotation of the product entity.
_form: '\Drupal\account_login\Plugin\Form\userloginForm'
-title: 'Two Way Authentication Login'
requirements:
_permission: 'access content'
_user_is_logged_in: 'FALSE'
account_login_otp.content: // We will use same route name for second tab which we use in 'links.task.yml' file
path: '/account/login/authenticate'
defaults:
# Calls the list controller, defined in the annotation of the product entity.
_form: '\Drupal\account_login\Plugin\Form\userloginotpForm'
-title: 'Login Form Authenticate'
requirements:
_permission: 'access content'
_user_is_logged_in: 'FALSE'
Now just we have to install custom module and and clear the cache then put the first URL on brower (Ex: /account/login) and its will show our Tabs. So simple way to easily create custom tabs.
Note: What is Namespace and Use keyword in drupal 8 module?
1. "module_name.links.task.yml" and "module_name.routing.yml" is important file, if we are going to create tabs.
2. Now Please follow the syntax, we will explain here for all parameters and syntax for tabs.
Example Syntax: Here 'account_login' is example of my module name..
account_login.tab_1: // This is the Tab Routers
route_name : account_login.content // This is route name and we will use this in routing.yml file when we create routers and path
title: account login // This is Title of Tabs.
base_route: account_login.content // This is for set default open Tab
weight: 10 // This is for tab weight or for order of Tab
account_login.tab_2: // This is for second Tab Router
route_name: account_login_otp.content // This is route name and we will use this in routing.yml file when we create routers and path
title: Work // This is Title of Tabs.
base_route: account_login.content // This is for set default open Tab
weight: 20 // This is for tab weight or for order of Tab
Now we will create "routing.yml" file.
Example Syntax: Here 'account_login' is example of my module name..
account_login.content: // so we will use same route name for first tab which we use in 'links.task.yml' file
path: '/account/login'
defaults:
# Calls the list controller, defined in the annotation of the product entity.
_form: '\Drupal\account_login\Plugin\Form\userloginForm'
-title: 'Two Way Authentication Login'
requirements:
_permission: 'access content'
_user_is_logged_in: 'FALSE'
account_login_otp.content: // We will use same route name for second tab which we use in 'links.task.yml' file
path: '/account/login/authenticate'
defaults:
# Calls the list controller, defined in the annotation of the product entity.
_form: '\Drupal\account_login\Plugin\Form\userloginotpForm'
-title: 'Login Form Authenticate'
requirements:
_permission: 'access content'
_user_is_logged_in: 'FALSE'
Now just we have to install custom module and and clear the cache then put the first URL on brower (Ex: /account/login) and its will show our Tabs. So simple way to easily create custom tabs.
Note: What is Namespace and Use keyword in drupal 8 module?