Sometimes to get the views exposed form and place into somewhere in the site. So we can use the below code to achieve programmatically.
$view = Views::getView('view_name');
$view->setDisplay('display_name');
$view->initHandlers();
$form_state = (new FormState())
->setStorage([
'view' => $view,
'display' => &$view->display_handler->display,
'rerender' => TRUE,
])
->setMethod('get')
->setAlwaysProcess()
->disableRedirect();
$form_state->set('rerender', NULL);
$form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state);
Web Development Information [PHP, DRUPAL, MYSQL, MAGENTO, JQUERY, JAVASCRIPT, CSS, HTML5]
Thursday, December 6, 2018
Wednesday, May 24, 2017
Download drupal contributed module in Drupal 8 using composer
Use the following commands to download and install in drupal 8 contributed module using Composer.
composer require drupal/{module_name} {version}
Example: composer require drupal/devel 1.0-beta1
Once execute the above command, this will download the module (not installed). For install, we need the execute the drush or drupal console command to install the module.
Via Drush: drush en {module_name}
Via Drupal console: drupal module:install {module_name}
composer require drupal/{module_name} {version}
Example: composer require drupal/devel 1.0-beta1
Once execute the above command, this will download the module (not installed). For install, we need the execute the drush or drupal console command to install the module.
Via Drush: drush en {module_name}
Via Drupal console: drupal module:install {module_name}
Tuesday, May 23, 2017
Clear the cache in Drupal 8
We can clear the cache in Drupal 8 in many ways
1. Via CMS end
Go to Administration > Configuration > Development > Performance (/admin/config/development/performance)
Click the button "Clear all caches"
2. Drupal console
drupal cache:rebuild all
3. Drush
drush cache-rebuild / drush cr
1. Via CMS end
Go to Administration > Configuration > Development > Performance (/admin/config/development/performance)
Click the button "Clear all caches"
2. Drupal console
drupal cache:rebuild all
3. Drush
drush cache-rebuild / drush cr
Monday, May 22, 2017
Create custom module in Drupal 8 via Drupal console
Generate module
drupal generate:module - It will ask the module name and basic information.
Give the module a name of module (welcome) and Enter module description, path and basic information. Then drupal will create the below files under the your custom module.
composer.json
welcome.info.yml
welcome.module
Install module
The module now exists but it is not enabled. You don’t need to go to the module page to enable it, you can install and enable the welcome module using the module:install command:
drupal module:install welcome
This will install the module and automatically rebuild the cache.
drupal generate:module - It will ask the module name and basic information.
Give the module a name of module (welcome) and Enter module description, path and basic information. Then drupal will create the below files under the your custom module.
composer.json
welcome.info.yml
welcome.module
Install module
The module now exists but it is not enabled. You don’t need to go to the module page to enable it, you can install and enable the welcome module using the module:install command:
drupal module:install welcome
This will install the module and automatically rebuild the cache.
Monday, April 11, 2016
List out CCK field allowed values in Drupal
List out CCK field allowed values in Drupal
$field = field_info_field('field_machine_name');
$allowed_values = list_allowed_values($field);
This will return the allowed values list as array.
Usage:
field_info_field - Load the field instance by using field machine name
list_allowed_values - List out the allowed values
$field = field_info_field('field_machine_name');
$allowed_values = list_allowed_values($field);
This will return the allowed values list as array.
Usage:
field_info_field - Load the field instance by using field machine name
list_allowed_values - List out the allowed values
Subscribe to:
Posts (Atom)