SlideShare a Scribd company logo
Conditional fields
How we ported the module to Drupal 8
Olga Rabodzei
orabodzei@adyax.com
2017
What this
module can do?
Conditional Fields allows you to
manage sets of dependencies
between fields.
It’s a user interface to the States
API.
2
Use case
3
What else this module can do?
4
Create a condition
5
What is "condition"?
● Filled
The dependee has at least one non-empty value
● Touched
The dependee has received focus at least once.
● Focused
The dependee is currently focused.
● Checked
The dependee is a checkbox and is checked.
● Empty
The dependee has an empty value.
● Untouched
The dependee has never received focus.
● Unfocused
The dependee is currently not focused.
● Unchecked
The dependee is a checkbox and is not checked.
This is the condition that dependee should meet to trigger the dependency.
Available options:
● Value: The dependee has a certain value or set of values
6
Condition settings
7
Values input mode
● Widget
Use the actual form widget to insert the desired values.
This is a quick but limited way to set up simple dependencies.
● Regular expression
Use a text field to insert a regular expression.
● All these values (AND)
Use a text area to insert a list of values.
● Any of these values (OR)
Use a text area to insert a list of values.
● Only one of these values (XOR)
Use a text area to insert a list of values.
● None of these values (NOT)
Use a text area to insert a list of values.
8
Problem 1 - Where
store a condition?
9
Dependency
configuration
All configuration of CF is stored
in entity_form_display like
third_party_settings for the field
field_music_other:
weight: 2
settings:
size: 60
placeholder: ''
third_party_settings:
conditional_fields:
28206ab7-29a2-4d26-a3e6-f24703a04cec:
dependee: field_music
settings:
state: visible
condition: value
grouping: AND
values_set: 1
value: ''
values: { }
value_form:
-
value: other
effect: show
effect_options: { }
selector: ''
entity_type: node
bundle: article
type: string_textfield
region: content
10
Problem 2 -
understand Drupal 7
magic
11
General rules of applying conditions
12
Current state based on Drupal 7
● hook_element_info_alter()
● conditional_fields_element_after_build()
● conditional_fields_attach_dependency()
ToDo for Drupal 8
● Simplify and refactor this.
● Create a separate controller.
Problem 3 - widget
input mode
13
In the Field API
Each field has a type, which determines what kind of data (integer, string, date, etc.) the
field can hold, which settings it provides, and so on.
The Field Types API also defines two kinds of pluggable handlers: widgets and formatters.
Widgets - in edit forms.
Formatters - in displayed entities.
14
CF Handler API
15
CF Handler API plugins
16
Problem 4 - time on
checking
17
Need for tests
18
Small example
protected function setUp() {
parent::setUp();
$this->fieldSelector = '[name="field_' .
$this->fieldName . '[0][value]"]';
$fieldStorageDefinition = [
'field_name' => 'field_' . $this->fieldName,
'entity_type' => 'node',
'type' => 'text',
'cardinality' => 1,
];
$fieldStorage =
FieldStorageConfig::create($fieldStorageDefinition)
;
$fieldStorage->save();
FieldConfig::create([
'field_name' => 'field_' . $this->fieldName,
'entity_type' => 'node',
'bundle' => 'article',
])->save();
EntityFormDisplay::load('node.article.default')
->setComponent('field_' . $this->fieldName,
['type' => 'text_textfield'])
->save();
}
Create in setUp() function all
that You need for a test: user,
content types, fields and etc.
19
Small example
protected function waitUntilVisible(
$selector,
$timeout = 1000,
$message = '')
{
$condition = "jQuery('{$selector}').is(':visible');";
$this->assertJsCondition($condition, $timeout, $message);
}
protected function waitUntilHidden(
$selector,
$timeout = 1000,
$message = '')
{
$condition = "jQuery('{$selector}').is(':hidden');";
$this->assertJsCondition($condition, $timeout, $message);
}
protected function changeField($selector, $value = '')
{
$script =
"jQuery('{$selector}').val('{$value}').trigger('keyup').trigger('change'
);"
$this->getSession()->executeScript($script);
}
Some useful small functions
20
Tests need and small example
public function testVisibleValueWidget() {
$this->baseTestSteps();
// Visit a ConditionalFields configuration page for Content bundles.
$this->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value');
// Set up conditions.
$text = $this->getRandomGenerator()->word(8);
$data = [
'[name="condition"]' => 'value',
'[name="values_set"]' => 1,
$this->fieldSelector => $text,
'[name="grouping"]' => 'AND',
'[name="state"]' => 'visible',
'[name="effect"]' => 'show',
];
foreach ($data as $selector => $value) {
$this->changeField($selector, $value);
}
$this->getSession()->wait(1000, '!jQuery.active');
$this->getSession()
->executeScript("jQuery('#conditional-field-edit-form').submit();");
$this->assertSession()->statusCodeEquals(200);
// Check if that configuration is saved.
$this->drupalGet('admin/structure/types/manage/article/conditionals');
$this->assertSession()
->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible
value');
// Visit Article Add form to check that conditions are applied.
$this->drupalGet('node/add/article');
$this->assertSession()->statusCodeEquals(200);
// Check that the field Body is not visible.
$this->waitUntilHidden('.field--name-body', 0, 'Article Body field is
visible');
$this->changeField($this->fieldSelector, $text);
$this->waitUntilVisible('.field--name-body', 50, 'Article Body field is
not visible');
// Change a select value set to hide the body again.
$this->changeField($this->fieldSelector, $text . 'a');
$this->waitUntilHidden('.field--name-body', 50, 'Article Body field is
visible');
}
Remember - just reproduce your steps like a user!
21
Plans and further development
● Bug fixing :)
● More refactoring.
● Finish all tests.
● Create new handler plugins if they are needed.
● Create a submodule for applying conditions on entity view display.
● Apply conditions depending on user roles.
● Investigate possibility to extend with “Dynamic dependent fields”.
22
Conditional fields
How we ported the module to Drupal 8
Olga Rabodzei
orabodzei@adyax.com
2017
Use case
24

More Related Content

What's hot

Going with style: Themes and apps for Magento Go
Going with style: Themes and apps for Magento GoGoing with style: Themes and apps for Magento Go
Going with style: Themes and apps for Magento Go
X.commerce
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
Yehuda Katz
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
Anton Kril
 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
DrupalCamp Kyiv
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
Fwdays
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
Fwdays
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
Bastian Feder
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf Conference
 
Vaadin JPAContainer
Vaadin JPAContainerVaadin JPAContainer
Vaadin JPAContainer
cmkandemir
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
Eric Maxwell
 
Drupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.xDrupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.x
Oleksandr Milkovskyi
 
Jquery plugin development
Jquery plugin developmentJquery plugin development
Jquery plugin development
Faruk Hossen
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
Yongjun Kim
 
Hibernate
HibernateHibernate
Hibernate
Leonardo Passos
 
Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시
Junha Jang
 
Coding website
Coding websiteCoding website
Coding website
PutuMahendra Wijaya
 
Bacbkone js
Bacbkone jsBacbkone js
Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시
Junha Jang
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
iamdangavin
 

What's hot (20)

Going with style: Themes and apps for Magento Go
Going with style: Themes and apps for Magento GoGoing with style: Themes and apps for Magento Go
Going with style: Themes and apps for Magento Go
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICESONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
ONE MORE TIME ABOUT CODE STANDARDS AND BEST PRACTICES
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Vaadin JPAContainer
Vaadin JPAContainerVaadin JPAContainer
Vaadin JPAContainer
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
 
Drupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.xDrupal node access system & AUL 7.x.-2.x
Drupal node access system & AUL 7.x.-2.x
 
Jquery plugin development
Jquery plugin developmentJquery plugin development
Jquery plugin development
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
 
Hibernate
HibernateHibernate
Hibernate
 
Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시Flask 소수전공 강의자료 - 4차시
Flask 소수전공 강의자료 - 4차시
 
Coding website
Coding websiteCoding website
Coding website
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시Flask 소수전공 강의자료 - 3차시
Flask 소수전공 강의자료 - 3차시
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
 

Similar to Conditional fields - Olga Riabodzei

iOS Talks 6: Unit Testing
iOS Talks 6: Unit TestingiOS Talks 6: Unit Testing
iOS Talks 6: Unit Testing
Marin Benčević
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
Mateusz Tymek
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
Gary Hockin
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
icubesystem
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
Mike Bartlett
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
vrluckyin
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas Smith
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
Dzmitry Ivashutsin
 
Dependency Injection in Laravel
Dependency Injection in LaravelDependency Injection in Laravel
Dependency Injection in Laravel
HAO-WEN ZHANG
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
Noveo
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
Jonathan Wage
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
John Cleveley
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetup
Anton Kropp
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
go_oh
 
Validation type 'special' in value sets
Validation type 'special' in value setsValidation type 'special' in value sets
Validation type 'special' in value sets
Feras Ahmad
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
Jason Ragsdale
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
Pragya Rastogi
 
Java script best practices v4
Java script best practices v4Java script best practices v4
Java script best practices v4
Thor Jørund Nydal
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
Sergey Bolshchikov
 

Similar to Conditional fields - Olga Riabodzei (20)

iOS Talks 6: Unit Testing
iOS Talks 6: Unit TestingiOS Talks 6: Unit Testing
iOS Talks 6: Unit Testing
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Dependency Injection in Laravel
Dependency Injection in LaravelDependency Injection in Laravel
Dependency Injection in Laravel
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Angular js meetup
Angular js meetupAngular js meetup
Angular js meetup
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Validation type 'special' in value sets
Validation type 'special' in value setsValidation type 'special' in value sets
Validation type 'special' in value sets
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
70562 (1)
70562 (1)70562 (1)
70562 (1)
 
Java script best practices v4
Java script best practices v4Java script best practices v4
Java script best practices v4
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 

More from DrupalCamp Kyiv

Speed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout BuilderSpeed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout Builder
DrupalCamp Kyiv
 
Performance Monitoring with Google Lighthouse
Performance Monitoring with Google LighthousePerformance Monitoring with Google Lighthouse
Performance Monitoring with Google Lighthouse
DrupalCamp Kyiv
 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
DrupalCamp Kyiv
 
Acquia BLT for the Win, or How to speed up the project setup, development an...
Acquia BLT for the Win, or  How to speed up the project setup, development an...Acquia BLT for the Win, or  How to speed up the project setup, development an...
Acquia BLT for the Win, or How to speed up the project setup, development an...
DrupalCamp Kyiv
 
Upgrading to Drupal 9
Upgrading to Drupal 9Upgrading to Drupal 9
Upgrading to Drupal 9
DrupalCamp Kyiv
 
THE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REALTHE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REAL
DrupalCamp Kyiv
 
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDFRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
DrupalCamp Kyiv
 
DRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCHDRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCH
DrupalCamp Kyiv
 
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
DrupalCamp Kyiv
 
Blackfire Workshop
Blackfire WorkshopBlackfire Workshop
Blackfire Workshop
DrupalCamp Kyiv
 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
DrupalCamp Kyiv
 
1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO
DrupalCamp Kyiv
 
UX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATIONUX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATION
DrupalCamp Kyiv
 
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
DrupalCamp Kyiv
 
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERATECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
DrupalCamp Kyiv
 
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPALPROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
DrupalCamp Kyiv
 
DRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTRDRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTR
DrupalCamp Kyiv
 
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
DrupalCamp Kyiv
 
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONSSEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
DrupalCamp Kyiv
 
DEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCE
DEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCEDEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCE
DEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCE
DrupalCamp Kyiv
 

More from DrupalCamp Kyiv (20)

Speed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout BuilderSpeed up the site building with Drupal's Bootstrap Layout Builder
Speed up the site building with Drupal's Bootstrap Layout Builder
 
Performance Monitoring with Google Lighthouse
Performance Monitoring with Google LighthousePerformance Monitoring with Google Lighthouse
Performance Monitoring with Google Lighthouse
 
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
Oleg Bogut - Decoupled Drupal: how to build stable solution with JSON:API, Re...
 
Acquia BLT for the Win, or How to speed up the project setup, development an...
Acquia BLT for the Win, or  How to speed up the project setup, development an...Acquia BLT for the Win, or  How to speed up the project setup, development an...
Acquia BLT for the Win, or How to speed up the project setup, development an...
 
Upgrading to Drupal 9
Upgrading to Drupal 9Upgrading to Drupal 9
Upgrading to Drupal 9
 
THE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REALTHE INTERNET OF THINGS IS GETTING REAL
THE INTERNET OF THINGS IS GETTING REAL
 
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLDFRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
FRONT-END COMPONENTS IN DRUPAL THEME. "KAIZEN" - DRUPAL 8 THEME FROM SKILLD
 
DRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCHDRUPAL AND ELASTICSEARCH
DRUPAL AND ELASTICSEARCH
 
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
WHAT WE LEARNED FROM OPEN SOCIAL IN 3 YEARS, MOVING FROM AN AGENCY TO A PRODU...
 
Blackfire Workshop
Blackfire WorkshopBlackfire Workshop
Blackfire Workshop
 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
 
1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO1-1 MEETING: STEP-BY-STEP-HOW-TO
1-1 MEETING: STEP-BY-STEP-HOW-TO
 
UX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATIONUX DURING MODULE INSTALLATION AND CONFIGURATION
UX DURING MODULE INSTALLATION AND CONFIGURATION
 
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
SWITCHING FROM QA ENGINEER TO PROJECT MANAGER - LEVEL UP OR DOWN?
 
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERATECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
TECHNOLOGIES-POWERED WEB AND THE POST-BROWSER ERA
 
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPALPROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
PROTECTED CONTENT: END-TO-END PGP ENCRYPTION FOR DRUPAL
 
DRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTRDRUPAL AUDITS MADE FASTR
DRUPAL AUDITS MADE FASTR
 
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
FROM DISTRO TO CUSTOM - HOW WE CREATE GREAT COMMUNITIES FOR EVERY ORGANIZATIO...
 
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONSSEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
SEARCH API: TIPS AND TRICKS - FROM BEGINNING TO CUSTOM SOLUTIONS
 
DEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCE
DEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCEDEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCE
DEVOPS & THE DEATH AND REBIRTH OF CHILDHOOD INNOCENCE
 

Recently uploaded

20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 

Recently uploaded (20)

20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 

Conditional fields - Olga Riabodzei

  • 1. Conditional fields How we ported the module to Drupal 8 Olga Rabodzei orabodzei@adyax.com 2017
  • 2. What this module can do? Conditional Fields allows you to manage sets of dependencies between fields. It’s a user interface to the States API. 2
  • 4. What else this module can do? 4
  • 6. What is "condition"? ● Filled The dependee has at least one non-empty value ● Touched The dependee has received focus at least once. ● Focused The dependee is currently focused. ● Checked The dependee is a checkbox and is checked. ● Empty The dependee has an empty value. ● Untouched The dependee has never received focus. ● Unfocused The dependee is currently not focused. ● Unchecked The dependee is a checkbox and is not checked. This is the condition that dependee should meet to trigger the dependency. Available options: ● Value: The dependee has a certain value or set of values 6
  • 8. Values input mode ● Widget Use the actual form widget to insert the desired values. This is a quick but limited way to set up simple dependencies. ● Regular expression Use a text field to insert a regular expression. ● All these values (AND) Use a text area to insert a list of values. ● Any of these values (OR) Use a text area to insert a list of values. ● Only one of these values (XOR) Use a text area to insert a list of values. ● None of these values (NOT) Use a text area to insert a list of values. 8
  • 9. Problem 1 - Where store a condition? 9
  • 10. Dependency configuration All configuration of CF is stored in entity_form_display like third_party_settings for the field field_music_other: weight: 2 settings: size: 60 placeholder: '' third_party_settings: conditional_fields: 28206ab7-29a2-4d26-a3e6-f24703a04cec: dependee: field_music settings: state: visible condition: value grouping: AND values_set: 1 value: '' values: { } value_form: - value: other effect: show effect_options: { } selector: '' entity_type: node bundle: article type: string_textfield region: content 10
  • 11. Problem 2 - understand Drupal 7 magic 11
  • 12. General rules of applying conditions 12 Current state based on Drupal 7 ● hook_element_info_alter() ● conditional_fields_element_after_build() ● conditional_fields_attach_dependency() ToDo for Drupal 8 ● Simplify and refactor this. ● Create a separate controller.
  • 13. Problem 3 - widget input mode 13
  • 14. In the Field API Each field has a type, which determines what kind of data (integer, string, date, etc.) the field can hold, which settings it provides, and so on. The Field Types API also defines two kinds of pluggable handlers: widgets and formatters. Widgets - in edit forms. Formatters - in displayed entities. 14
  • 16. CF Handler API plugins 16
  • 17. Problem 4 - time on checking 17
  • 19. Small example protected function setUp() { parent::setUp(); $this->fieldSelector = '[name="field_' . $this->fieldName . '[0][value]"]'; $fieldStorageDefinition = [ 'field_name' => 'field_' . $this->fieldName, 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, ]; $fieldStorage = FieldStorageConfig::create($fieldStorageDefinition) ; $fieldStorage->save(); FieldConfig::create([ 'field_name' => 'field_' . $this->fieldName, 'entity_type' => 'node', 'bundle' => 'article', ])->save(); EntityFormDisplay::load('node.article.default') ->setComponent('field_' . $this->fieldName, ['type' => 'text_textfield']) ->save(); } Create in setUp() function all that You need for a test: user, content types, fields and etc. 19
  • 20. Small example protected function waitUntilVisible( $selector, $timeout = 1000, $message = '') { $condition = "jQuery('{$selector}').is(':visible');"; $this->assertJsCondition($condition, $timeout, $message); } protected function waitUntilHidden( $selector, $timeout = 1000, $message = '') { $condition = "jQuery('{$selector}').is(':hidden');"; $this->assertJsCondition($condition, $timeout, $message); } protected function changeField($selector, $value = '') { $script = "jQuery('{$selector}').val('{$value}').trigger('keyup').trigger('change' );" $this->getSession()->executeScript($script); } Some useful small functions 20
  • 21. Tests need and small example public function testVisibleValueWidget() { $this->baseTestSteps(); // Visit a ConditionalFields configuration page for Content bundles. $this->createCondition('body', 'field_' . $this->fieldName, 'visible', 'value'); // Set up conditions. $text = $this->getRandomGenerator()->word(8); $data = [ '[name="condition"]' => 'value', '[name="values_set"]' => 1, $this->fieldSelector => $text, '[name="grouping"]' => 'AND', '[name="state"]' => 'visible', '[name="effect"]' => 'show', ]; foreach ($data as $selector => $value) { $this->changeField($selector, $value); } $this->getSession()->wait(1000, '!jQuery.active'); $this->getSession() ->executeScript("jQuery('#conditional-field-edit-form').submit();"); $this->assertSession()->statusCodeEquals(200); // Check if that configuration is saved. $this->drupalGet('admin/structure/types/manage/article/conditionals'); $this->assertSession() ->pageTextContains('body ' . 'field_' . $this->fieldName . ' visible value'); // Visit Article Add form to check that conditions are applied. $this->drupalGet('node/add/article'); $this->assertSession()->statusCodeEquals(200); // Check that the field Body is not visible. $this->waitUntilHidden('.field--name-body', 0, 'Article Body field is visible'); $this->changeField($this->fieldSelector, $text); $this->waitUntilVisible('.field--name-body', 50, 'Article Body field is not visible'); // Change a select value set to hide the body again. $this->changeField($this->fieldSelector, $text . 'a'); $this->waitUntilHidden('.field--name-body', 50, 'Article Body field is visible'); } Remember - just reproduce your steps like a user! 21
  • 22. Plans and further development ● Bug fixing :) ● More refactoring. ● Finish all tests. ● Create new handler plugins if they are needed. ● Create a submodule for applying conditions on entity view display. ● Apply conditions depending on user roles. ● Investigate possibility to extend with “Dynamic dependent fields”. 22
  • 23. Conditional fields How we ported the module to Drupal 8 Olga Rabodzei orabodzei@adyax.com 2017