Skip to main content

Posts

Showing posts from November, 2017

How to call non-static method from static method of same class?

You must create a new object inside the static method to access not-static methods inside that class: class Foo { public function fun1 () { echo 'non-static' ; } public static function fun2 () { echo ( new self )-> fun1 (); } } Reference:  https://stackoverflow.com/questions/41631623/how-to-call-non-static-method-from-static-method-of-same-class

How to get field settings in Drupal 8

To get settings of an Entity field in Drupal 8 Use this code: $entity_type='node'; $bundle='article'; $field_name='field_summary_image'; $bundle_fields = \Drupal::getContainer()->get('entity_field.manager')->getFieldDefinitions($entity_type, $bundle); $field_definition = $bundle_fields[$field_name]; $file_directory= $field_definition->getSetting('file_directory');

How to run jQuery code before Drupal ajax submit call

To run some jQuery code before the Ajax button submit use beforeSubmit function Drupal . behaviors . exampleModule = { attach : function ( context , settings ) { // ELEMENT_ID must not include the # Drupal . ajax [ 'ELEMENT_ID' ]. options . beforeSubmit = function ( form_values , element_settings , options ) { // code here }; } };