Created
October 4, 2017 07:40
-
-
Save woprrr/12c8f1f503a55d33236c8b1659320050 to your computer and use it in GitHub Desktop.
Drupal 8 Dynamic field cardinality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$field_updated = &$form['YOUR_FIELD_NAME']; | |
$field_state = \Drupal\Core\Field\WidgetBase::getWidgetState($form['#parents'], $field_updated['widget']['#field_name'], $form_state); | |
// You can change number of item to control the number of items we can change it with another field value into $form_state. | |
if ($field_state['items_count'] >= 2) { | |
$field_updated['widget']['add_more']['#access'] = FALSE; | |
} | |
$form['YOUR_FIELD_NAME'] = $field_updated; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment