class Message

Same name in this branch
  1. 10 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
Same name in other branches
  1. 9 composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
  2. 9 core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
  3. 8.9.x composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
  4. 8.9.x core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message
  5. 11.x composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
  6. 11.x core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message

Determine configuration.

@internal

Hierarchy

  • class \Drupal\Composer\Plugin\ProjectMessage\Message

Expanded class hierarchy of Message

1 file declares its use of Message
ConfigTest.php in core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
42 string references to 'Message'
AjaxTestController::renderError in core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
Returns an AjaxResponse with alert command.
ConfigEntityImportTest::doActionUpdate in core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
Tests updating an action during import.
ConfigEntityValidationTestBase::testInvalidMachineNameCharacters in core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php
Tests that the entity's ID is tested for invalid characters.
ConfigExportUITest::testExport in core/modules/config/tests/src/Functional/ConfigExportUITest.php
Tests export of configuration.
ConnectionFailureTest::testConnectionFailureLogging in core/modules/dblog/tests/src/Kernel/ConnectionFailureTest.php
Tests logging of connection failures.

... See full list

File

composer/Plugin/ProjectMessage/Message.php, line 12

Namespace

Drupal\Composer\Plugin\ProjectMessage
View source
class Message {
    
    /**
     * The root package.
     *
     * @var \Composer\Package\RootPackageInterface
     */
    protected $rootPackage;
    
    /**
     * The name of the event.
     *
     * @var string
     */
    protected $eventName;
    
    /**
     * The message to display.
     *
     * @var string[]
     */
    protected $messageText = [];
    
    /**
     * Construct a Config object.
     *
     * @param \Composer\Package\RootPackageInterface $root_package
     *   Composer package object for the root package.
     * @param string $event_name
     *   The event name.
     */
    public function __construct(RootPackageInterface $root_package, $event_name) {
        $this->rootPackage = $root_package;
        $this->eventName = $event_name;
    }
    public function getText() {
        if ($this->messageText) {
            return $this->messageText;
        }
        $package_config = $this->rootPackage
            ->getExtra();
        $file = $this->eventName . '-message.txt';
        if ($config_file = $package_config['drupal-core-project-message'][$this->eventName . '-file'] ?? FALSE) {
            $file = $config_file;
        }
        $message = $package_config['drupal-core-project-message'][$this->eventName . '-message'] ?? [];
        if ($message) {
            $this->messageText = $message;
        }
        else {
            $this->messageText = $this->getMessageFromFile($file);
        }
        // Include structured support info from composer.json.
        if ($config_keys = $package_config['drupal-core-project-message']['include-keys'] ?? FALSE) {
            foreach ($config_keys as $config_key) {
                switch ($config_key) {
                    case 'name':
                        if ($homepage = $this->rootPackage
                            ->getName()) {
                            $this->messageText[] = '  * Name: ' . $homepage;
                        }
                        break;
                    case 'description':
                        if ($homepage = $this->rootPackage
                            ->getDescription()) {
                            $this->messageText[] = '  * Description: ' . $homepage;
                        }
                        break;
                    case 'homepage':
                        if ($homepage = $this->rootPackage
                            ->getHomepage()) {
                            $this->messageText[] = '  * Homepage: ' . $homepage;
                        }
                        break;
                    case 'support':
                        if ($support = $this->rootPackage
                            ->getSupport()) {
                            $this->messageText[] = '  * Support:';
                            foreach ($support as $support_key => $support_value) {
                                $this->messageText[] = '    * ' . $support_key . ': ' . $support_value;
                            }
                        }
                        break;
                }
            }
        }
        return $this->messageText;
    }
    
    /**
     * Reads the message file as an array.
     *
     * @param string $file
     *   The file to read. Relative paths are relative to the project directory.
     *
     * @return string[]
     */
    protected function getMessageFromFile($file) {
        return file_exists($file) ? file($file, FILE_IGNORE_NEW_LINES) : [];
    }

}

Members

Title Sort descending Modifiers Object type Summary
Message::$eventName protected property The name of the event.
Message::$messageText protected property The message to display.
Message::$rootPackage protected property The root package.
Message::getMessageFromFile protected function Reads the message file as an array.
Message::getText public function
Message::__construct public function Construct a Config object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.