Я думаю, что простое решение - добавить пользовательскую проверку в форму узла: когда пользователь пытается отправить новый узел (страницу, статью ...), проверьте, не опубликовали ли они до 3 статей на этой неделе, если да - > остановить форму от отправки данных, если нет -> сохранить новый узел.
Вот мое решение в коде, которое должно быть размещено в вашем пользовательском модуле:
- Реализация hook_form_alter для добавления пользовательской проверки
function MY_MODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// check if user is about to create new node of type page
// This custom validation won't be called on EDIT form (edit form_id is node_page_edit_form)
if($form_id == 'node_page_form') {
$form['#validate'][] = '_node_page_form_custom_validate';
}
}
- В пользовательской функции проверки проверьте, опубликовал ли текущий пользователь до 3 статей на этой неделе
function _node_page_form_custom_validate(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
// 1. get current user id
$user_uid = \Drupal::currentUser()->id();
// 2. count number of nodes created by current user in last week
$query = \Drupal::entityQuery('node');
$query->condition('type', array('page', 'article'), 'IN'); // Limit the type of node to check
$query->condition('uid', $user_uid);
$first_day_of_week = strtotime('Last Monday'); // choose the day you define as First day of week
$last_day_of_week = strtotime('Next Monday');
$query->condition('created', array($first_day_of_week, $last_day_of_week), 'BETWEEN');
$count = $query->count()->execute();
// 3. if number of posts reachs limit, stop the form from saving data
if($count >= 3) {
$form_state->setErrorByName('', t('You reached the limit of @count pages/articles this week', array('@count' => $count)));
}
}
Надеюсь, это поможет.