Sharp Context

Sharp provide a way to grab some request context values in the application code.

Ask for context

The class handling the context is Code16\Sharp\Http\Context\CurrentSharpRequest, which is a singleton. So at any point in the request, you can get it via:

app(Code16\Sharp\Http\Context\CurrentSharpRequest::class);

or with the global helper:

currentSharpRequest();

Here's a quick example:

class MyForm extends SharpForm
{
    function buildFormFields()
    {
        $this->addField(
            SharpFormTextField::make("name")
                ->setReadOnly(currentSharpRequest()->isUpdate())
        );
        [...]
    }
    [...]
}

The context is often useful in a Form situation to display or hide fields depending on the instance status (creation, update), or in a Validator to add an ID exception in a "unique" rule.

Methods

entityKey(): string

Grab the current entity key.

isEntityList(): bool

isShow(): bool

isForm(): bool

Find out the current page type.

isUpdate(): bool

isCreation(): bool

In Form case, check the current status.

instanceId(): string

In Form and Show cases, grab the instance id.

Returns a Collection of Code16\Sharp\Http\Context\Util\BreadcrumbItems

getCurrentBreadcrumbItem(): BreadcrumbItem

Get the current breadcrumb item.

getPreviousShowFromBreadcrumbItems(?string $entityKey = null): ?BreadcrumbItem

Get (if existing) the closest Show in the breadcrumb.

globalFilterFor($filterName)

Get the value of a Global Filter: see the Global Filter documentation to know more about this feature.

Last Updated:
Contributors: philippe