Utility.php in Menu Item Extras 8.2
File
src/Utility/Utility.php
View source
<?php
namespace Drupal\menu_item_extras\Utility;
use Drupal\Component\Utility\Unicode;
class Utility {
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;
}
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);
}
public static function suggestion($str1, $str2 = '') {
return self::limitUnderscores(implode('__', func_get_args()));
}
public static function limitUnderscores($str) {
return preg_replace('/__+/', '__', $str);
}
}
Classes
Name |
Description |
Utility |
Utility functions specific to menu_item_extras. |