use Civi\API\Exception\NotImplementedException;
use Civi\Api4\Generic\BasicGetAction;
-use Civi\Api4\Utils\ActionUtil;
use Civi\Api4\Utils\ReflectionUtils;
/**
- * Get actions for an entity with a list of accepted params
+ * Get all API actions for the $ENTITY entity.
+ *
+ * Includes a list of accepted parameters for each action, descriptions and other documentation.
*/
class GetActions extends BasicGetAction {
if (is_dir($dir)) {
foreach (glob("$dir/*.php") as $file) {
$matches = [];
- preg_match('/(\w*).php/', $file, $matches);
+ preg_match('/(\w*)\.php$/', $file, $matches);
$actionName = array_pop($matches);
$actionClass = new \ReflectionClass('\\Civi\\Api4\\Action\\' . $this->_entityName . '\\' . $actionName);
if ($actionClass->isInstantiable() && $actionClass->isSubclassOf('\\Civi\\Api4\\Generic\\AbstractAction')) {
private function loadAction($actionName, $method = NULL) {
try {
if (!isset($this->_actions[$actionName]) && (!$this->_actionsToGet || in_array($actionName, $this->_actionsToGet))) {
- $action = ActionUtil::getAction($this->getEntityName(), $actionName);
+ $action = \Civi\API\Request::create($this->getEntityName(), $actionName, ['version' => 4]);
if (is_object($action)) {
$this->_actions[$actionName] = ['name' => $actionName];
if ($this->_isFieldSelected('description', 'comment', 'see')) {
+ $vars = ['entity' => $this->getEntityName(), 'action' => $actionName];
// Docblock from action class
- $actionDocs = ReflectionUtils::getCodeDocs($action->reflect());
+ $actionDocs = ReflectionUtils::getCodeDocs($action->reflect(), NULL, $vars);
unset($actionDocs['method']);
// Docblock from action factory function in entity class. This takes precedence since most action classes are generic.
if ($method) {
- $methodDocs = ReflectionUtils::getCodeDocs($method, 'Method');
- $actionDocs = $methodDocs + $actionDocs;
+ $methodDocs = ReflectionUtils::getCodeDocs($method, 'Method', $vars);
+ // Allow method doc to inherit class doc
+ if (strpos($method->getDocComment(), '@inheritDoc') !== FALSE && !empty($methodDocs['comment']) && !empty($actionDocs['comment'])) {
+ $methodDocs['comment'] .= "\n\n" . $actionDocs['comment'];
+ }
+ $actionDocs = array_filter($methodDocs) + $actionDocs;
}
$this->_actions[$actionName] += $actionDocs;
}