Add isAvailable method to the ToolInterface and ToolBase
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3555051. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
Related to !74 !62
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>We will have tools that only really should work if certain pre-requirements are set.</p>
<p>For instance if we have a tool that can search Google for you, via SERPApi then we would want to make sure that the SERPApi key is set. Meaning that you have setup the module correctly, after installation.</p>
<p>Or if you have a tool that does video encoding/decoding, you might need FFMpeg installed on the server. It should not be available before that happens.</p>
<p>The <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21ImageToolkit%21ImageToolkitInterface.php/function/ImageToolkitInterface%3A%3AisAvailable/11.x">ImageToolKit</a> has something similar already, where it checks the GD or ImageMagick libraries if certain parts are compiled with it, to make sure that it can manipulate images in the way the user wants it to. We should use this as the base of how we set it up.</p>
<p>I think that any plugin returning false on if the tool is available should log a warning message why its not available. But I do not know if that could become annoying if you have a module with 4 tools, where you only want to setup one of them. There is also no way of forcing a log message in the method, and having two extra methods for this seems overkill.</p>
<p>Depending on if you want it to still show up for instance in checkbox listing, but be disabled, we have to decide if the inactive tools should be hidden or tagged.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<ul>
<li>Decide if isAvailable is the correct name, or if isExecutable or something else fits better.</li>
<li>Add an isAvailable method to the ToolInterface, that returns bool.</li>
<li>Add an isAvailable method to the ToolBase that just returns true.</li>
<li>Only run this when using getDefinition(s), to make sure that this check is cached.</li>
<li>Decide if the result of this should hide the tool from getDefinition(s), or if we should dynamically add an attribute to it.</li>
</ul>
> Related issue: [Issue #3558327](https://www.drupal.org/node/3558327)
issue