Skip to content
Snippets Groups Projects
Commit 5ed605bd authored by surgemartin's avatar surgemartin Committed by Martin Anderson-Clutz
Browse files

Issue #3174274 by josh.fabean, mandclu: Smartdate does not work on Custom Entities

parent df27fbd7
No related branches found
No related tags found
No related merge requests found
......@@ -439,7 +439,7 @@ function smart_date_recur_form_field_config_edit_form_alter(&$form, FormStateInt
$form['third_party_settings']['smart_date_recur']['month_limit'] = [
'#type' => 'number',
'#title' => t('Months to Extend'),
'#description' => t('For recurring dates without a specified end, how many months out should instances be generated?'),
'#description' => t('For recurring dates without a specified end, how many months out should instances be generated? If left empty or zero, a default value of 12 will be used.'),
'#states' => [
// Show this textarea only if the 'repeat' select has a value.
'visible' => [
......
......@@ -69,7 +69,7 @@ class Instances extends ControllerBase {
$field_name = $this->rrule->field_name->getString();
if ($this->rrule->limit->isEmpty()) {
$month_limit = $this->rrule->getFieldSettings('month_limit');
$month_limit = SmartDateRule::getMonthsLimit($this->rrule);
$before = strtotime('+' . (int) $month_limit . ' months');
}
else {
......
......@@ -205,7 +205,7 @@ class SmartDateRule extends ContentEntityBase {
* Generate default instances based on rule structure.
*/
public function getNewInstances() {
$month_limit = $this->getFieldSettings('month_limit');
$month_limit = $this->getMonthsLimit($this);
$before = strtotime('+' . (int) $month_limit . ' months');
$instances = $this->getStoredInstances();
$last_instance = end($instances);
......@@ -499,6 +499,25 @@ class SmartDateRule extends ContentEntityBase {
];
}
/**
* Retrieve the months_limit value from the field definition.
*/
public static function getMonthsLimit($field_def) {
$month_limit = NULL;
if (method_exists($field_def, 'getThirdPartySetting')) {
// Works for field definitions and rule objects.
$month_limit = $field_def
->getThirdPartySetting('smart_date_recur', 'month_limit');
}
elseif (method_exists($field_def, 'getSetting')) {
// For custom entities, set value in your field definition.
$month_limit = $field_def->getSetting('month_limit');
}
// Default to 12 if no value provided.
$month_limit = $month_limit ?: 12;
return $month_limit;
}
/**
* Return an array of frequency labels.
*/
......
......@@ -301,8 +301,7 @@ class SmartDateWidgetBase extends DateTimeWidgetBase {
if ($allow_recurring && function_exists('smart_date_recur_widget_extra_fields')) {
// Provide extra parameters to be stored with the recurrence rule.
$month_limit = $field_def
->getThirdPartySetting('smart_date_recur', 'month_limit');
$month_limit = SmartDateRule::getMonthsLimit($field_def);
if ($form_state->getFormObject() instanceof EntityFormInterface) {
$entity = $form_state->getformObject()->getEntity();
$entity_type = $entity->getEntityTypeId();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment