public function PartyStorageController::setLabel in Party 8.2
Set the label on a Party object using the first label plugin (when ordered by weight) that returns a non-empty value.
This method optionally saves the label to the database as well as generating it, this allows the function to be called independantly of party save. Also, as most Party label plugins require the party to be saved to function correctly, this avoids having to go through the Party::save() method multiple times.
Parameters
Party $party: A party object.
bool $store: Whether we should store the new label.
1 call to PartyStorageController::setLabel()
- PartyStorageController::invokeHook in lib/
Drupal/ party/ PartyStorageController.php - Implements EntityAPIControllerInterface.
File
- lib/
Drupal/ party/ PartyStorageController.php, line 73 - Definition of Drupal\party\PartyStorageController.
Class
- PartyStorageController
- Controller class for users.
Namespace
Drupal\partyCode
public function setLabel($party, $store = TRUE) {
module_load_include('inc', 'party', 'party.admin');
// Get the label plugins.
$label_plugins = party_settings_get_party_label_plugins();
// Try each plugin, lowest weight first, until a plugin is
// found that returns a non-empty value.
foreach ($label_plugins as $path => $label_plugin) {
$label_callback = $label_plugin['label callback'];
$label = $label_callback($party);
if (!empty($label)) {
$party->label = $label;
break;
}
}
// No label plugins returned a label, use the party id if possible.
if (empty($label) && isset($party->id)) {
$party->label = t('Party @pid', array(
'@pid' => $party->id,
));
}
if ($store && isset($party->pid)) {
// Save the label to the database.
db_query('UPDATE {party} SET label = :label WHERE pid = :pid', array(
':label' => $party->label,
':pid' => $party
->id(),
));
$this
->invokeHook('update', $party);
}
}