function auto_entitylabel_is_needed in Automatic Entity Label 7
Returns whether the auto entitylabel has to be set on the provided entity.
Parameters
object $entity: A Drupal entity object.
string $entity_type: The entity type.
bool $reset: Force set the label, even if a title already exists.
Return value
bool Return TRUE if needed.
3 calls to auto_entitylabel_is_needed()
- auto_entitylabel_entity_insert in ./
auto_entitylabel.module - Implements hook_entity_insert().
- auto_entitylabel_entity_presave in ./
auto_entitylabel.module - Implements hook_entity_presave().
- auto_entitylabel_entity_update_action in ./
auto_entitylabel.module - Update action wrapper.
File
- ./
auto_entitylabel.module, line 234 - Allows hiding of entity label fields and automatic label creation.
Code
function auto_entitylabel_is_needed($entity, $entity_type, $reset = FALSE) {
// First, we'll attempt to get the entity type specific settings.
$settings = _auto_entitylabel_get_settings($entity, $entity_type);
// Stub out a few rules we'll need to verify in addition to the $reset flag.
// Do we have configs for this entity type?
$has_settings = $settings && !empty($settings['key']) && ($setting = auto_entitylabel_get_setting($settings['key']));
// We can't do much if there are no settings.
if ($has_settings) {
// Is the label empty?
$empty_label = empty($entity->{$settings['title']}) || $entity->{$settings['title']} == AUTO_ENTITYLABEL_PLACEHOLDER || empty($entity->auto_entitylabel_applied);
// Is the auto label optional?
$label_optional = $setting == AUTO_ENTITYLABEL_OPTIONAL;
// Check if the label is empty or forced.
// Then makes sure an existing label isn't overwritten if the autolabel is
// optional.
return ($empty_label || $reset) && !($label_optional && !$empty_label);
}
// The above conditions where not met so we'll return "false".
return FALSE;
}