class Utility in Menu Item Extras 8.2
Utility functions specific to menu_item_extras.
Hierarchy
- class \Drupal\menu_item_extras\Utility\Utility
Expanded class hierarchy of Utility
3 files declare their use of Utility
- MenuItemExtrasViewModeSelectorSelect.php in src/
Plugin/ Field/ FieldWidget/ MenuItemExtrasViewModeSelectorSelect.php - menu_item_extras.module in ./
menu_item_extras.module - Manage fields for the menu items.
- UtilityTest.php in tests/
src/ Unit/ UtilityTest.php
1 string reference to 'Utility'
1 service uses Utility
File
- src/
Utility/ Utility.php, line 10
Namespace
Drupal\menu_item_extras\UtilityView source
class Utility {
/**
* Checks if bundle and entity fields are different.
*
* @param string $entity_type
* Entity type for checking.
* @param string $bundle
* Bundle for checking.
*
* @return bool
* Returns TRUE if bundle has other fields than entity.
*/
public static function checkBundleHasExtraFieldsThanEntity($entity_type, $bundle) {
$entity_manager = \Drupal::service('entity_field.manager');
$bundle_fields = array_keys($entity_manager
->getFieldDefinitions($entity_type, $bundle));
$entity_type_fields = array_keys($entity_manager
->getBaseFieldDefinitions($entity_type));
if ($bundle_fields !== $entity_type_fields) {
return TRUE;
}
return FALSE;
}
/**
* Sanitize string.
*
* @param string $string
* Input string.
*
* @return string
* Sanitized string.
*/
public static function sanitizeMachineName($string) {
$to_replace = [
' ',
'-',
'.',
];
$string = str_replace($to_replace, array_fill(0, count($to_replace), '_'), mb_strtolower($string));
$string = preg_replace('/[^A-Za-z0-9\\_]/', '', $string);
return self::limitUnderscores($string);
}
/**
* Suggestion builder, based on recieved args.
*
* @param string $str1
* Argument for string building.
* @param string $str2
* Add arguments as more as you need.
*
* @return string
* Prepared suggestion string.
*/
public static function suggestion($str1, $str2 = '') {
return self::limitUnderscores(implode('__', func_get_args()));
}
/**
* Filter more than 2 underscores in the row.
*
* @param string $str
* Input string.
*
* @return null|string
* Filtered string.
*/
public static function limitUnderscores($str) {
return preg_replace('/__+/', '__', $str);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Utility:: |
public static | function | Checks if bundle and entity fields are different. | |
Utility:: |
public static | function | Filter more than 2 underscores in the row. | |
Utility:: |
public static | function | Sanitize string. | |
Utility:: |
public static | function | Suggestion builder, based on recieved args. |