Skip to content

Commit

Permalink
Merge pull request #323 from robbiejackson/include-di-links
Browse files Browse the repository at this point in the history
Module Tutorial - remove helper at start, and update links to explanatory sections.
  • Loading branch information
robbiejackson authored Nov 14, 2024
2 parents a29bc61 + 444ab39 commit a27244a
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Put into mod_hello/services/provider.php the following code:

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -79,13 +78,12 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
};
```

If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in a later step of the tutorial.
If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in the [Dependency Injection](step8-dependency-injection.md) step of the tutorial.

### Dispatcher File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HelloHelper

There are 2 ways we can get access to our HelloHelper class.
In this step we'll access it directly using Namespacing.
When we later look at dependency injection we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.
When we later look at [Dependency Injection](step8-dependency-injection.md) we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.

```php title="mod_hello/src/Dispatcher/Dispatcher.php"
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ These 3 DIC entries are used so often that Joomla provides a shorthand way of en

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
// highlight-next-line
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
Expand All @@ -172,6 +173,7 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
// highlight-next-line
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ The source code is available at [mod_hello step 9](https://github.com/joomla/man

## com_ajax

Joomla provides a component `com_ajax` (described [here](https://docs.joomla.org/Using_Joomla_Ajax_Interface)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

:::caution todo
Update link above when com_ajax documentation is moved to the manual
:::
Joomla provides a component `com_ajax` (described [here](../../../general-concepts/javascript/com-ajax.md)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

In the javascript code we make an Ajax call to `index.php?option=com_ajax&module=hello&method=count&format=json`.
The URL parameters are interpreted as follows
Expand All @@ -43,11 +39,7 @@ com_ajax->>helper:countAjax()
helper->>com_ajax:result
```

When com_ajax receives the result it uses the Joomla [JsonResponse](https://docs.joomla.org/JSON_Responses_with_JResponseJson) class to return the result to the javascript code.

:::caution todo
Update link above when JsonResponse documentation is moved to the manual
:::
When com_ajax receives the result it uses the Joomla [JsonResponse](../../../general-concepts/javascript/ajax.md) class to return the result to the javascript code.

## mod_hello changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Put into mod_hello/services/provider.php the following code:

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -79,13 +78,12 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
};
```

If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in a later step of the tutorial.
If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in the [Dependency Injection](step8-dependency-injection.md) step of the tutorial.

### Dispatcher File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HelloHelper

There are 2 ways we can get access to our HelloHelper class.
In this step we'll access it directly using Namespacing.
When we later look at dependency injection we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.
When we later look at [Dependency Injection](step8-dependency-injection.md) we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.

```php title="mod_hello/src/Dispatcher/Dispatcher.php"
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ These 3 DIC entries are used so often that Joomla provides a shorthand way of en

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
// highlight-next-line
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
Expand All @@ -172,6 +173,7 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
// highlight-next-line
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ The source code is available at [mod_hello step 9](https://github.com/joomla/man

## com_ajax

Joomla provides a component `com_ajax` (described [here](https://docs.joomla.org/Using_Joomla_Ajax_Interface)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

:::caution todo
Update link above when com_ajax documentation is moved to the manual
:::
Joomla provides a component `com_ajax` (described [here](../../../general-concepts/javascript/com-ajax.md)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

In the javascript code we make an Ajax call to `index.php?option=com_ajax&module=hello&method=count&format=json`.
The URL parameters are interpreted as follows
Expand All @@ -43,11 +39,7 @@ com_ajax->>helper:countAjax()
helper->>com_ajax:result
```

When com_ajax receives the result it uses the Joomla [JsonResponse](https://docs.joomla.org/JSON_Responses_with_JResponseJson) class to return the result to the javascript code.

:::caution todo
Update link above when JsonResponse documentation is moved to the manual
:::
When com_ajax receives the result it uses the Joomla [JsonResponse](../../../general-concepts/javascript/ajax.md) class to return the result to the javascript code.

## mod_hello changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Put into mod_hello/services/provider.php the following code:

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -79,13 +78,12 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
};
```

If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in a later step of the tutorial.
If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in the [Dependency Injection](step8-dependency-injection.md) step of the tutorial.

### Dispatcher File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HelloHelper

There are 2 ways we can get access to our HelloHelper class.
In this step we'll access it directly using Namespacing.
When we later look at dependency injection we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.
When we later look at [Dependency Injection](step8-dependency-injection.md) we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.

```php title="mod_hello/src/Dispatcher/Dispatcher.php"
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ These 3 DIC entries are used so often that Joomla provides a shorthand way of en

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
// highlight-next-line
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
Expand All @@ -172,6 +173,7 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
// highlight-next-line
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ The source code is available at [mod_hello step 9](https://github.com/joomla/man

## com_ajax

Joomla provides a component `com_ajax` (described [here](https://docs.joomla.org/Using_Joomla_Ajax_Interface)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

:::caution todo
Update link above when com_ajax documentation is moved to the manual
:::
Joomla provides a component `com_ajax` which allows a module's javascript code to make an Ajax call and get back an Ajax response.

In the javascript code we make an Ajax call to `index.php?option=com_ajax&module=hello&method=count&format=json`.
The URL parameters are interpreted as follows
Expand All @@ -43,11 +39,7 @@ com_ajax->>helper:countAjax()
helper->>com_ajax:result
```

When com_ajax receives the result it uses the Joomla [JsonResponse](https://docs.joomla.org/JSON_Responses_with_JResponseJson) class to return the result to the javascript code.

:::caution todo
Update link above when JsonResponse documentation is moved to the manual
:::
When com_ajax receives the result it uses the Joomla JsonResponse class to return the result to the javascript code.

## mod_hello changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Put into mod_hello/services/provider.php the following code:

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -79,13 +78,12 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
};
```

If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in a later step of the tutorial.
If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in the [Dependency Injection](step8-dependency-injection.md) step of the tutorial.

### Dispatcher File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HelloHelper

There are 2 ways we can get access to our HelloHelper class.
In this step we'll access it directly using Namespacing.
When we later look at dependency injection we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.
When we later look at [Dependency Injection](step8-dependency-injection.md) we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.

```php title="mod_hello/src/Dispatcher/Dispatcher.php"
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ These 3 DIC entries are used so often that Joomla provides a shorthand way of en

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
// highlight-next-line
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
Expand All @@ -172,6 +173,7 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
// highlight-next-line
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ The source code is available at [mod_hello step 9](https://github.com/joomla/man

## com_ajax

Joomla provides a component `com_ajax` (described [here](https://docs.joomla.org/Using_Joomla_Ajax_Interface)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

:::caution todo
Update link above when com_ajax documentation is moved to the manual
:::
Joomla provides a component `com_ajax` (described [here](../../../general-concepts/javascript/com-ajax.md)) which allows a module's javascript code to make an Ajax call and get back an Ajax response.

In the javascript code we make an Ajax call to `index.php?option=com_ajax&module=hello&method=count&format=json`.
The URL parameters are interpreted as follows
Expand All @@ -43,11 +39,7 @@ com_ajax->>helper:countAjax()
helper->>com_ajax:result
```

When com_ajax receives the result it uses the Joomla [JsonResponse](https://docs.joomla.org/JSON_Responses_with_JResponseJson) class to return the result to the javascript code.

:::caution todo
Update link above when JsonResponse documentation is moved to the manual
:::
When com_ajax receives the result it uses the Joomla [JsonResponse](../../../general-concepts/javascript/ajax.md) class to return the result to the javascript code.

## mod_hello changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ Put into mod_hello/services/provider.php the following code:

use Joomla\CMS\Extension\Service\Provider\Module as ModuleServiceProvider;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory as ModuleDispatcherFactoryServiceProvider;
use Joomla\CMS\Extension\Service\Provider\HelperFactory as HelperFactoryServiceProvider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -79,13 +78,12 @@ return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->registerServiceProvider(new ModuleDispatcherFactoryServiceProvider('\\My\\Module\\Hello'));
$container->registerServiceProvider(new HelperFactoryServiceProvider('\\My\\Module\\Hello\\Site\\Helper'));
$container->registerServiceProvider(new ModuleServiceProvider());
}
};
```

If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in a later step of the tutorial.
If you're new to Joomla development then this code probably looks very intimidating. If so, the best thing is just to accept it for now. It's just boilerplate code that is used to link the Joomla core code with our mod_hello extension. We'll explain it in the [Dependency Injection](step8-dependency-injection.md) step of the tutorial.

### Dispatcher File

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class HelloHelper

There are 2 ways we can get access to our HelloHelper class.
In this step we'll access it directly using Namespacing.
When we later look at dependency injection we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.
When we later look at [Dependency Injection](step8-dependency-injection.md) we'll change the code to use the alternative method of getting it instantiated via a HelperFactory class.

```php title="mod_hello/src/Dispatcher/Dispatcher.php"
<?php
Expand Down
Loading

0 comments on commit a27244a

Please sign in to comment.